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.md3. Used by agents' projects
Dependency in 648 public GitHub projects set up for AI coding agents that we scanned (10.4%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
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
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
Often used with
date-fns in practice
Strengths
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>.
The README says date-fns uses the native <code>Date</code> type and "doesn't extend core objects for safety's sake."
The maintainers write that the library is "Built using pure functions and always returns a new date instance."
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
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>.
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.
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
Head to head
- date-fns vs Day.js used together in 21 projects
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
Alternatives
date-fns This page
Pick Day.js when you want a very small library with a chained, Moment.js-like style.
Pick Luxon when you want one DateTime object with time zones and formatting built in, rather than separate helpers.
Pick the Temporal polyfill to write code against JavaScript's new standard date API today.
Modular utility library with methods for common programming tasks and data manipulation.
Parse, validate, manipulate and format dates and times in JavaScript.
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.”
Add date-fns to your project.
npm install date-fns --saveFrom github.com/date-fns/date-fns/blob/main/pkgs/core/docs/gettingStarted.md
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
For time zones, add the companion package and use TZDate.
npm install @date-fns/tz --saveFrom github.com/date-fns/date-fns/blob/main/pkgs/tz/README.md
Rules for your agent
## 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
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.
date-fns 4 has its own time zone package; the docs point to date-fns-tz only for older versions.
The CDN files inside date-fns are deprecated, log a notice and are removed in version 5.
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.