This indicates the difference between two date-time in the specified unit.
To get the difference in milliseconds, use
const date1 = dayjs('2019-01-25') const date2 = dayjs('2018-06-05') date1.diff(date2) // 20214000000 default milliseconds
To get the difference in another unit of measurement, pass that measurement as the second argument.
const date1 = dayjs('2019-01-25') date1.diff('2018-06-05', 'month') // 7
Units are case insensitive, and support plural and short forms.
List of all available units
|Day of Week (Sunday as 0, Saturday as 6)|
|Week of Year|
|Month (January as 0, December as 11)|
dayjs#diff will truncate the result to zero decimal places, returning an integer. If you want a floating point number, pass true as the third argument.
const date1 = dayjs('2019-01-25') date1.diff('2018-06-05', 'month', true) // 7.645161290322581