DateDiff()
Determines the integer number of units by which date1 is less than date2.
DateDiff( datePart=string, date1=datetime, date2=datetime );
Returns: Number
Argument | Description |
---|---|
datePart
string,
required
|
The specific units in which to count:
|
date1
datetime,
required
|
date object; for example, now() |
date2
datetime,
required
|
date object; for example, now() |
Examples
echo( DateDiff( "d", "2016-06-27", "2016-06-28" ) & "<br>" ); // 1
echo( DateDiff( "d", "2016-06-27", "2016-06-27" ) & "<br>" ); // 0
echo( DateDiff( "d", "2016-06-27", "2016-06-26" ) & "<br>" ); // -1
echo( DateDiff( "h", "2016-06-27 00:00:00", "2016-06-27 01:00:00" ) & "<br>" ); // 1
echo( DateDiff( "h", "2016-06-27 00:00:00", "2016-06-27 00:00:00" ) & "<br>" ); // 0
echo( DateDiff( "h", "2016-06-27 01:00:00", "2016-06-27 00:00:00" ) & "<br>" ); // -1
echo( DateDiff( "wd", "2016-06-27 00:00:00", "2016-07-27 01:00:00" ) & "<br>" ); // 22
See also
- Date and time
- datetime.diff()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)