Date.diff
$date.diff($fromDate='now', $unit='seconds') -> number
Description
Return the duration of time between the Date object and $fromDate.
$fromDate can be one of the following:
- Date object
- Date string (e.g. “2021-10-17”, “now”, “3 days ago”). See Date Strings.
- Unix timestamp (integer)
$fromDate is the point of reference, to determine if this date object comes before (negative) or after (positive).
$now = Date.now()
$futureDate = $now.add('2 hours')
$pastDate = $now.add('-1 hour')
$futureDate.diff()
//= 7200 (seconds)
$pastDate.diff($futureDate, 'hours')
//= 3
$futureDate.diff($pastDate, 'hours')
//= -3