New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

date-difference-lib

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-difference-lib

The library calculates the difference in years, months, and days

latest
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

Date Difference Library

This library provides a function to calculate the difference between two dates in years, months, and days.

npm badge

Installation

To use this library in your project, you can install it via npm:

npm install date-difference-lib

Usage:

JS Project:

const { getDateDifference } = require('date-difference-lib');
console.log(getDateDifference("2023-01-01", "2024-01-01"));

React / Angular / Vue (TypeScript):

import { getDateDifference } from 'date-difference-lib';

const diff = getDateDifference("2023-01-01", "2024-01-01", { asObject: true });

console.log(diff.years); // 1

console.log(getDateDifference('2020-01-01', '2023-10-15'));  // Output: "3 years, 9 months, 14 days"

console.log(getDateDifference('2022-05-05', '2023-05-06'));  // Output: "1 year, 1 day"

Accepted formats:

getDateDifference(new Date(2024, 0, 1), new Date(2024, 1, 1));

getDateDifference('2023-01-01', '2024-01-01', { utc: false });

// Returns the difference as object
getDateDifference("2024-01-01T10:00:00Z", "2024-02-01T10:00:00Z", { asObject: true });

getDateDifference(1704067200000, 1706745600000);

// negative difference preserved
getDateDifference('2024-01-01', '2023-01-01', { signed: true }); 

console.log(getDateDifference('2024-01-01', '2023-01-01', { includeTime: true, includeZeroUnits: true }));
// "1 year, 0 months, 0 days, 0 hours, 0 minutes, 0 seconds"

https://www.npmjs.com/package/date-difference-lib?activeTab=readme

Keywords

date

FAQs

Package last updated on 04 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts