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

Date.diffHuman

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

Description

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

It always includes a positive whole number.

$now = Date.now()

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

$almostMinute = $now.add(58, 'secs')
$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