← All libraries

date-fns

JavaScript
↗ Official site

Utilities & helpers

Everything you need to work with dates in JavaScript.

What it does

date-fns gives you hundreds of functions for formatting, comparing, and manipulating dates. Working with dates in JavaScript is notoriously annoying — this library fixes that.

When to use it

Use this when you need to format dates, calculate durations, or compare timestamps.

Real example

You're building a booking app and need to show 'Booking in 3 days' or 'Booking was 2 hours ago'. Prompt: 'Use date-fns formatDistanceToNow() to display how far each booking.date is from now. If the date is in the future, show it in green. If past, show it in red.'

Good to know

Lighter and more modular than Moment.js (which is now deprecated). Use date-fns or Day.js for new projects.

Alternatives

Day.js Temporal (native)

Install

$ npm install date-fns

Use cases

date formattingdate comparisoncalendarscheduling

Language

JavaScript

Category

Utilities & helpers

More in Utilities & helpers

Other tools in the same category