Returns the number of intervals between two dates.
Copy Code |
---|
long DateDiff ( |
The part parameter can have one of the following values:
Parameter Value | Description |
---|---|
y | The returned value specifies the difference between a and b, expressed in years. |
m | The returned value specifies the difference between a and b, expressed in months. |
d | The returned value specifies the difference between a and b, expressed in days. |
h | The returned value specifies the difference between a and b, expressed in hours. |
n | The returned value specifies the difference between a and b, expressed in minutes. |
s | The returned value specifies the difference between a and b, expressed in seconds. |
You can use the DateDiff function to determine how many specified time intervals exist between two dates. For example, use DateDiff to calculate the number of days between two dates.
If a refers to a later point in time than b, the DateDiff function returns a negative number.
When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("y") returns 1 even though only a day has elapsed.