You need to determine the difference between two dates or times.

Use DateDiff() to return the interval between two dates and/or times. The DateDiff() function is used to return the interval between two dates or times. The function takes three parameters, the interval for the comparison, and the two dates you want to compare.

The following code compares the difference between two dates in years, and the difference between two times in minutes:

<cfoutput>
#DateDiff("yyyy", "12/31/1999", "12/31/2002",)#<br>
#DateDiff("n", "12:00:00", "15:00:00")#
</cfoutput>

This interval can be expressed in a variety of formats:

Datepart Interval
s Second
n Minute
h Hour
ww Week
w Weekday
d Day
y Day of year
m Month
q Quarter
yyyy Year

DateDiff() returns the interval in the unit you specify by which the second date/time is greater than the first. If the first date is greater than the second, a negative number is returned.

This question was written by Rob Brooks-Bilson
It was last updated on January 6, 2006.

Categories

Dates/Times

Comments

comments powered by Disqus