Version: v0.8.1 - Beta.  We welcome contributors & feedback.

Date.diffHuman

$date.diffHuman($fromDate='now') -> string

Description

Return a human-readable string that contains the difference between this date and $fromDate.

It always includes a positive whole number.

$now = Date.now()

$otherDate = $now.add(50, 'hours')
$otherDate.diffHuman()
//= '2 days'

$almostMinute = $now.add(58, 'seconds')
$almostMinute.diffHuman()
//= '1 minute'

$longAgo = $now.add(-1000, 'days')
$longAgo.diffHuman()
//= '3 years'

$date1 = Date.create('50 days')
$date2 = Date.create('300 days ago')
$date1.diffHuman($date2)
//= '1 year'

See Also