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 install date-fns
yarn add date-fns
pnpm add date-fns
Import
import { format, addDays } from 'date-fns';Quick Example
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); // 7About 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
| Package | date-fns |
| Category | Utility |
| Weekly Downloads | 20M+ |
| License | MIT |
| Install | npm install date-fns |
Related Packages
Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting date…
Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates t…
Lodash is the most popular JavaScript utility library, providing a comprehensive collection of funct…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.