VistaDB 5
INT DATEDIFF( datepart, startdate, enddate )

Returns the number of intervals crossed between the two dates as specified by the Datepart. If you are interested in how many months are between two dates you would pass month as the datepart.

Return Type

The following are valid datepart parameters:

Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms


NOTE: startdate is subtracted from enddate. If startdate is later than enddate, a negative value is returned.

DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years.

The method of counting crossed boundaries such as minutes, seconds, and milliseconds makes the result specified by DATEDIFF consistent across all data types. The result is a signed integer value equal to the number of datepart boundaries crossed between the first and second date.


Result:  14

Result: 104
SELECT DATEDIFF(day, '01/01/2007', '04/15/2007')
SELECT DATEDIFF(week, '01/01/2007', '04/15/2007')
See Also