@cityssm/date-diff
v2.2.3
Published
Calculates the difference between two JavaScript Dates.
Downloads
233
Maintainers
Readme
date-diff
Calculates the difference between two JavaScript Dates.
Forked from melvinsembrano/date-diff.
Installation
npm install @cityssm/date-diff
Usage
Browser (ES2015)
<script>
window.exports = window.exports || {};
</script>
<script src="/path/to/date-diff/es2015/date-diff.min.js"></script>
<script>
const fromDate = new Date(2020, (1 - 1), 1); // 2020-01-01
const toDate = new Date(2021, (1 - 1), 1); // 2021-01-01
const diff = exports.dateDiff(fromDate, toDate);
</script>
Node 12 or better (ES Module)
import { dateDiff } from "@cityssm/date-diff";
const fromDate = new Date(2020, (1 - 1), 1); // 2020-01-01
const toDate = new Date(2021, (1 - 1), 1); // 2021-01-01
const diff = dateDiff(fromDate, toDate);
Output
diff = {
inMilliseconds: 31622400000,
inSeconds: 31622400,
inMinutes: 527040,
inHours: 8784,
inDays: 366,
inWeeks: 52.3,
inMonths: 12,
inYears: 1,
formatted: '1 year'
}