Skip to main content

@std/datetime@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function difference
difference(
from: Date,
to: Date,
): DifferenceFormat

Returns 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

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

Year to calculate difference

Year to calculate difference with

Options for determining how to respond

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/datetime

Import symbol

import { difference } from "@std/datetime";
or

Import directly with a jsr specifier

import { difference } from "jsr:@std/datetime";