User Guide
DateDiff 445
DateDiff
Description
Determines the integer number of units by which date1 is less than date2.
Returns
A number of units, of type datepart.
Category
Date and time functions
Function syntax
DateDiff("datepart", "date1", "date2")
See also
DateAdd, DatePart, CreateTimeSpan
History
ColdFusion MX:
• Changed how negative date differences are calculated: this function calculates negative date
differences correctly; its output may be different from that in earlier releases.
• Changed the w and ww attributes; they determine the number of full weeks between the two
dates.
Parameters
Usage
The DateDiff function determines the number of complete datepart units between the two
dates; for example, if the datepart parameter is "m" and the dates differ by 55 days, the function
returns 1.
Enclose string constant dates in quotation marks. If the text contains only numbers (such 1932),
and is not surrounded by quotation marks, ColdFusion interprets it as a date/time object,
resulting in an incorrect value.
Parameter Description
datepart String specifying the units in which to count; for example yyyy requests a date
difference in whole years.
• yyyy: Years
• q: Quarters
• m: Months
• y: Days of year (same as d)
• d: Days
• w: Weekdays (same as ww)
• ww: Weeks
• h: Hours
• n: Minutes
• s: Seconds
date1 Date/time object, in the range 100 AD–9999 AD.
date2 Date/time object, in the range 100 AD–9999 AD.