date-fns
v4.1.0MITTree-shakeableTS ReadyModern JavaScript date utility library like lodash for dates, modular and tree-shakeable.
98/ 100
Excellent Health
Weekly Downloads
19.8M
Bundle Size (gzip)
3.8 kB(12.5 kB min)
Dependencies
Zero Deps
Last Updated
2024-09-10
SPONSORED CLOUD & DEV TOOLSβ’Google Ads Partner
NPMBot AI Assessment
The Gold Standard of functional, immutable date manipulation in modern TypeScript.
Unlike Moment or Day.js, date-fns works directly on native JS Date instances using pure functions. Import only what you use (`import { format, addDays } from 'date-fns'`), and bundlers will strip everything else. Version 4 provides rock-solid ESM and TypeScript typing.
Key Advantages
- β’Native JavaScript Date objects: no custom wrapper classes needed
- β’Unbeatable tree-shaking: pay only for the exact functions imported
- β’Strictly immutable and side-effect free
- β’Superb TypeScript first implementation
Gotchas & Limitations
- β’Functional syntax (`format(addDays(new Date(), 3), 'yyyy-MM-dd')`) can be more verbose than chaining
Recommended For:
Modern React/Next.js/Vue codebases with bundle budgeting, Functional programming and strict TypeScript workflows
Avoid If:
Teams strongly preferring chained method syntax like `date.add().format()`
FEATURED PARTNERβ’Google Ads Partner
Installation & Quickstart
Package Manager Command
javascriptnpm install date-fnsdate-fns Usage Example
javascriptimport { format, addDays } from 'date-fns';
const formatted = format(addDays(new Date(), 7), 'yyyy-MM-dd');
console.log(formatted);Compare date-fns with Alternatives
Recommended Alternatives
SPONSORED SERVERSβ’Google Ads Partner