Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

date-fns

Format and calculate dates in JavaScript.

UtilitiesNPM

GitHub

1. License

“to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software”

Free for paid and closed products; keep the MIT notice with the package files.

github.com/date-fns/date-fns/blob/main/pkgs/core/LICENSE.md

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What date-fns does

date-fns is a free JavaScript package of small date helpers. Your app shows "2 days ago", counts working days to a delivery date or prints a date in German, French or Japanese. It works in the browser and in Node.js, and a companion package handles time zones.

What people build with it

"2 days ago" on comments

A feed or inbox shows how long ago each message came in, in the reader's language.

Delivery dates without weekends Idea

A shop shows "arrives Wednesday" by adding three working days to the order date and skipping Saturday and Sunday.

One meeting time for every city

An event page shows a 15:00 New York call as 21:00 in Berlin and 05:00 next day in Tokyo.

Dates in the reader's language

The same date shows as words in English, German or another language; you load only the languages you use.

Sort and compare dates in a list

Order bookings or posts by date before you show them.

Dates in file names and reports

Exports get names like report-2026-11-13.csv in a fixed, sortable form.

date-fns popularity

86 / 100
Gid Score, #26 overall
127M
downloads a week, npm
36.7K
GitHub stars
648
agent projects use it
date-fns: downloads per weeknpm, date-fns 127,238,007
date-fns: GitHub starsdate-fns/date-fns 36,663

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How date-fns is used

  • date-fns is a dependency in 648 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (13.3% of the 4,867 JavaScript/TypeScript ones), #2 of 408 in utilities.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 2,234; those are left out of every share on this page.
  • The most used alternative in our scan is Lodash (111 projects).
  • Projects that use it most often also use Lucide React (82.4%), clsx (81.3%), Tailwind Merge (79.6%).
  • It is more common in projects set up for Kiro (16.4%) than for OpenCode (7.3%).

By coding agent

360 projects, 14.7%
327 projects, 10.0%
279 projects, 9.2%
45 projects, 9.5%
41 projects, 8.7%
41 projects, 14.7%
25 projects, 7.3%
23 projects, 16.4%

Often used with

In 82.4% of its projects
In 81.3% of its projects
In 79.6% of its projects
In 76.4% of its projects
In 69.9% of its projects
In 92.1% of its projects
In 89.8% of its projects
In 61.6% of its projects

date-fns in practice

Strengths

200+ functions, Lodash-style

The README pitches date-fns as "like Lodash for dates" and says it has 200+ functions. Its own example shows functions such as <code>compareAsc</code> plugging directly into <code>dates.sort()</code>.

Leaves Date.prototype alone

The README says date-fns uses the native <code>Date</code> type and "doesn't extend core objects for safety's sake."

Returns new instances

The maintainers write that the library is "Built using pure functions and always returns a new date instance."

Modular, with locales to match

The README calls the library modular and says it works with webpack, Browserify or Rollup and supports tree-shaking. For i18n, it says there are "Dozens of locales. Include only what you need."

Watch out for

CDN scripts are deprecated

v4.4.0 deprecates the CDN scripts shipped in <code>date-fns</code>. They will be removed in the next major release, and in <code>v5.0.0-alpha.0</code> they are already gone. CDN users are told to move to <code>@date-fns/cdn</code>.

CDN source maps already removed

v4.4.0 removed the CDN source maps from <code>date-fns</code>. The release notes say <code>@date-fns/cdn</code> still includes them.

Package layout still changing

The maintainers say v4.4.0 allowed cutting the zipped package from <code>5.83 MB</code> to <code>3.96 MB</code>, and that v5.0.0-alpha.0 brings it to <code>2.89 MB</code>. They call this "just the first step" and say to expect further size reduction in v4 and v5.

Format a date and sort an array of dates

import { compareAsc, format } from "date-fns";

format(new Date(2014, 1, 11), "yyyy-MM-dd");
//=> '2014-02-11'

const dates = [
  new Date(1995, 6, 2),
  new Date(1987, 1, 11),
  new Date(1989, 6, 10),
];
dates.sort(compareAsc);
//=> [
//   Wed Feb 11 1987 00:00:00,
//   Mon Jul 10 1989 00:00:00,
//   Sun Jul 02 1995 00:00:00
// ]

More about date-fns

Funding
  • GitHub Sponsors: https://github.com/kossnocorp
  • Open Collective: https://opencollective.com/date-fns
  • 10 GitHub sponsors

See all

Head to head
Packages around it
  • lucide-react: Icon components
  • clsx: className builder
  • tailwind-merge: Tailwind class merging
  • class-variance-authority: Component variants
  • @radix-ui: UI primitives
  • react: UI library
More in Utilities

Alternatives

date-fns This page

MITGid 86127M/wk

Day.js

Pick Day.js when you want a very small library with a chained, Moment.js-like style.

MITGid 82117M/wk

Luxon

Pick Luxon when you want one DateTime object with time zones and formatting built in, rather than separate helpers.

temporal-polyfill

Pick the Temporal polyfill to write code against JavaScript's new standard date API today.

Lodash

Modular utility library with methods for common programming tasks and data manipulation.

MITGid 84212M/wk

Moment.js

Parse, validate, manipulate and format dates and times in JavaScript.

MITGid 7552.2M/wk

Compare date-fns with another tool

Get started

Tell your AI assistant

“Use date-fns 4.4.0 (and @date-fns/tz for time zones) to format and calculate these dates; use the tokens yyyy and dd, not YYYY and DD, and import only the locales the app needs.”

  1. Add date-fns to your project.

    npm install date-fns --save

    From github.com/date-fns/date-fns/blob/main/pkgs/core/docs/gettingStarted.md

  2. Import only the helpers you use and call them on normal JavaScript dates.

    import { formatDistance, subDays } from "date-fns";
    
    formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true });
    //=> "3 days ago"
    

    From github.com/date-fns/date-fns/blob/main/pkgs/core/docs/gettingStarted.md

  3. For time zones, add the companion package and use TZDate.

    npm install @date-fns/tz --save

    From github.com/date-fns/date-fns/blob/main/pkgs/tz/README.md

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## date-fns
- Install with `npm install date-fns --save`. Import functions by name, as the README does: `import { compareAsc, format } from "date-fns"`.
- Use the value a date-fns call returns. The README says the library "always returns a new date instance".
- To sort dates, pass the comparator directly, e.g. `dates.sort(compareAsc)`, as in the README example.
- For year-month-day output, follow the README's token casing `"yyyy-MM-dd"`. Do not copy `'yyyy-mm-dd'` from blog posts without checking the token in the docs.
- For date-only values that must not shift for users in other time zones, consider the Atomic Object approach: build dates from a string with date-fns `parse` instead of `new Date()`.
- Include only the locales the app needs. The README says "Dozens of locales. Include only what you need."
- For CDN usage, use `@date-fns/cdn`. The `date-fns` CDN scripts are deprecated and will be removed in the next major release.

Mistakes to avoid

format(date, 'YYYY-MM-DD')
format(date, 'yyyy-MM-dd')

YYYY is the week-numbering year and DD the day of the year; in our run date-fns 4.4.0 threw a RangeError for this.

Adding date-fns-tz for time zones in a date-fns 4 project
npm install @date-fns/tz and use TZDate or the in option

date-fns 4 has its own time zone package; the docs point to date-fns-tz only for older versions.

<script src="https://cdn.jsdelivr.net/npm/date-fns/cdn.min.js">
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js">

The CDN files inside date-fns are deprecated, log a notice and are removed in version 5.

Doing date math with new Date() on a server and expecting the user's local day
Create a TZDate in the user's time zone, or pass in tz('Zone/Name') to the helper

Plain dates use the server's time zone, so summer-time shifts and day borders come out wrong for users elsewhere.

Questions

Does date-fns handle time zones?

Yes, since version 4, through the separate @date-fns/tz package and its TZDate class.

Why does format(date, 'YYYY-MM-DD') throw an error?

YYYY is the week-numbering year and DD the day of the year; use yyyy-MM-dd. date-fns refuses those tokens unless you turn them on.

Does it change my Date objects?

No. Every helper returns a new date and leaves the one you passed alone.

Can I still use require() instead of import?

Yes. Version 4 is ESM-first but still ships CommonJS files.