function difference
difference(): DifferenceFormatReturns the difference of the 2 given dates in the given units. If the units are omitted, it returns the difference in the all available units.
Examples
Example 1
Example 1
import { difference } from "@std/datetime/difference"; const date0 = new Date("2018-05-14"); const date1 = new Date("2020-05-13"); difference(date0, date1, { units: ["days", "months", "years"] }); // => returns { days: 730, months: 23, years: 1 } difference(date0, date1); // => returns { // milliseconds: 63072000000, // seconds: 63072000, // minutes: 1051200, // hours: 17520, // days: 730, // weeks: 104, // months: 23, // quarters: 7, // years: 1 // }
Parameters
from: DateYear to calculate difference
to: DateYear to calculate difference with
optional
options: DifferenceOptionsOptions for determining how to respond