DateDiff()
Determines the integer number of units by which date1 is less than date2.
With Lucee 6, the order of the arguments for this .diff() member function was changed to match ACF
DateDiff( datePart=string, date1=datetime, date2=datetime );
Returns: Number
| Argument | Description |
|---|---|
|
datePart
string,
required
|
edit
The specific units in which to count:
|
|
date1
datetime,
required
|
edit
date object; for example, now() |
|
date2
datetime,
required
|
edit
date object; for example, now() |
Examples
editecho( 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 open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)