DateDiff

Determines the integer number of units by which date1 is less than date2.

Returns: number

Usage

DateDiff( datepart, date1, date2 )

Arguments

Argument Description
datepart
(string, required)

The specific units in which to count:

  • yyyy: Years
  • q: Quarters
  • m: Months
  • y: Days (same as d)
  • d: Days (same as y)
  • w: Weeks (same as ww)
  • ww: Weeks (same as w)
  • h: Hours
  • n: Minutes
  • s: Seconds
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

See also