🛠️
Utility20M+/wkMIT

date-fns

date-fns is a modern JavaScript date utility library that provides comprehensive, consistent, and modular functions for parsing, formatting, manipulating, and c

Installation

npm
npm install date-fns
yarn
yarn add date-fns
pnpm
pnpm add date-fns

Import

ESM
import { format, addDays } from 'date-fns';

Quick Example

usage
import { format, addDays, differenceInDays } from 'date-fns';

const today = new Date();
console.log(format(today, 'yyyy-MM-dd'));

const nextWeek = addDays(today, 7);
const diff = differenceInDays(nextWeek, today); // 7

About date-fns

date-fns is a modern JavaScript date utility library that provides comprehensive, consistent, and modular functions for parsing, formatting, manipulating, and comparing dates. Often described as the Lodash of dates, date-fns treats dates as immutable — every function returns a new Date instance rather than mutating the original. The library provides over 200 functions organized by category including format and parse for date formatting with Unicode tokens, add and sub for arithmetic, differenceInDays/Hours/Minutes for comparisons, startOfWeek/Month/Year for boundary calculations, isValid and isBefore/isAfter for validation, and locale support for over 60 languages. date-fns is fully tree-shakeable because each function is a separate ES module export, meaning your bundle only includes the functions you actually use. This is a significant advantage over Moment.js which bundles everything regardless of usage. date-fns uses native JavaScript Date objects rather than wrapper objects, ensuring compatibility with the entire JavaScript ecosystem. The library provides comprehensive TypeScript types and supports both ESM and CommonJS imports.

Quick Facts

Packagedate-fns
CategoryUtility
Weekly Downloads20M+
LicenseMIT
Installnpm install date-fns

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.