Date diff

node v10.24.1
version: master
endpointsharetweet
const startDate = '2020-01-01'; const endDate = '2020-03-15'; const diffInMs = new Date(endDate) - new Date(startDate) const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
const moment = require('moment'); const startDate = '2020-01-01'; const endDate = '2020-03-15'; const diffInDays = moment(endDate).diff(moment(startDate), 'days'); // https://momentjs.com/docs/#/displaying/difference/
const differenceInDays = require('date-fns/differenceInDays'); const startDate = '2020-01-01'; const endDate = '2020-03-15'; const diffInDays = differenceInDays(new Date(endDate), new Date(startDate)); // https://date-fns.org/v2.16.1/docs/differenceInDays
const { DateTime } = require('luxon'); const startDate = '2020-01-01'; const endDate = '2020-03-15'; const diffInDays = DateTime.fromISO(endDate).diff(DateTime.fromISO(startDate), 'days').toObject().days; // https://moment.github.io/luxon/docs/class/src/datetime.js~DateTime.html#instance-method-diff
Loading…

no comments

    sign in to comment