Returns a number of time intervals between two specified dates.
Overload
Parameters
| IntervalType value | Description |
|---|---|
| Yyyy | Year |
| Q | Quarter |
| M | Month |
| Y | Day of year |
| D | Day (both "y" and "d" find the difference in days) |
| W | Number of weeks between startDateTime and endDateTime |
| Ww | Number of firstDayOfWeek's between startDateTime and endDateTime |
| H | Hour |
| N | Minute |
| S | Second |
| Constant | Description |
|---|---|
| jrUseSystem | 0 (Use the current system date) |
| jrSunday | 1 |
| jrMonday | 2 |
| jrTuesday | 3 |
| jrWednesday | 4 |
| jrThursday | 5 |
| jrFriday | 6 |
| jrSaturday | 7 |
Return value
A Number value.
Examples
DateDiff("d", ToDateTime(1999,10,7), ToDateTime(1999,10,10)) - Returns 3
DateDiff("yyyy", ToDateTime(1999,10,7), ToDateTime(2005,2,10)) - Returns 6.DateDiff("yyyy", ToDateTime(1999,12,31), ToDateTime(2000,1,1)) - Returns 1 (a 1 year difference), even though there is only a 1 day difference between the dates.DateDiff("yyyy", ToDateTime(1999,1,1), ToDateTime(1999,12,31)) - Returns 0 (a 0 year difference), even though there is a 364 days difference.Suppose that for the above examples, the first date is the date that you bought a mutual fund, and the second date is the date you sold it. The mutual fund company must send you an annual report for every year in which you owned units in the fund. You would then get 7, 2 and 1 annual reports respectively, in the above cases.
DateDiff("q", ToDateTime(1999,10,6), ToDateTime(2003,5,20)) - Returns 14.DateDiff("q", ToDateTime(1999,3,31), ToDateTime(1999,4,1)) - Returns 1. The two dates are in adjacent quarters.DateDiff("q", ToDateTime(1999,1,1), ToDateTime(1999,3,31)) - Returns 0. The two dates are in the same quarter.Suppose the mutual fund company in the "yyyy" example mailed out quarterly reports. It would need to mail out 15, 2 and 1 quarterly reports respectively, in the above cases.
DateDiff("m", ToDateTime(1999,3,15), ToDateTime(1999,7,13)) - Returns 4.
DateDiff("w", ToDateTime(1999,10,19), ToDateTime(1999,10,25)) - Returns 0.DateDiff("w", ToDateTime(1999,10,19), ToDateTime(1999, 10,26)) - Returns 1.