Calculate difference between two dates, with the resolution of days.
Run as a command line program.
npm install -g date-differ
date-differ [-f] <date> [[-t] <date>] [-d]
Calculate difference between two dates. Result is relative, for years, months and days, or absolute days.
Parameters:
-f, --from, Date from, valid JavaScript date format
-t, --to, Date to, valid JavaScript date format
-d, --days, Only print days
$ date-differ -f 2020-11-24 -t 2020-12-24
1 month
$ date-differ -f 2020-11-24 -t 2020-12-24 -d
30 days
Use in a node script.
npm install date-differ
const dateDiffer = require("date-differ");
The functions takes an object as its only parameter:
{
from, // String, a parsable date, defaults to today
to, // String, a parsable date, defaults to today
days, // Boolean, optional, return only days
}
const result = dateDiffer({
from: "2020-11-24",
to: 1608764400000, // 2020-12-24 in milliseconds since Unix Epoch
});
console.log(result); // 1 month
const result = dateDiffer({
from: "2020-11-24",
to: "2020-12-24T15:00:00",
days: true,
});
console.log(result); // 30 days