Modern JavaScript date utility library

date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
import { format, formatDistance, formatRelative, subDays } from 'date-fns'

format(new Date(), "'Today is a' eeee")
//=> "Today is a Wednesday"

formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"

formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
Why date-fns?
  1. Modular

    With the function-per-file style, you can pick just what you need and stop bloating your project with useless functionality.

    It works well with modern module bundlers such as webpack, Browserify, and Rollup and also supports tree-shaking.

  2. Native Date

    date-fns uses the native Date type and doesn't reinvent the wheel. It doesn't extend core objects for safety's sake.

    Functions in date-fns work predictably and stick to ECMAScript behavior in edge cases.

  3. Immutable & Pure

    date-fns is built using pure functions and always returns a new date instance instead of changing the passed one.

    It helps to prevent bugs and avoid long debugging sessions.

  4. TypeScript & Flow

    date-fns supports both TypeScript and Flow.

    The typings are generated from the source code and bundled with the package, so they're always up-to-date.

  5. FP
    The functional programming submodule provides a better alternative to chaining: composition; which makes your code clean and safe and doesn't bloat your build.
  6. I18n
    With support from the amazing community, date-fns has dozens of locales. Only the ones that you use will be included in your project.
  7. Consistent

    date-fns always returns a date in the same time zone, no matter what's passed - a timestamp, a string or a date object.

    The API is tailored to have predictable names and arguments order.

  8. Reliable

    date-fns respects timezones & DST.

    It follows semantic versioning so, always backward compatible.

    Each build CI checks more than 650 000 examples in about 400 time zones.

  9. Simple

    The best API is an API that doesn't exist. With date-fns you always have one function that does one thing.

    The API is unambiguous, and there is always a single approach to a problem.

  10. Fast
    In addition to tiny size, date-fns is fast. You can be sure that your users will have the best user experience.
  11. Docs
    Every date-fns function has a detailed description with examples. The documentation is accessible both online on the website and offline thanks to JSDoc annotations.
  12. More Coming!
    date-fns is an active development and we are constantly adding new features.
date-fns is the modular path to date/time manipulation. Where I work, it helped us get our bundle sizes down, especially because we are able to include only the functionality we need.
date-fns gave us the power to work directly with date objects, without worrying about conversion or mutations. It's a real game changer for dates.
Sasha and Lesha Koss made what anyone dealing with dates in JS ever wanted, but didn’t got the time, the knowledge or the courage! Because of stars like date-fns the dev community is becoming an amazing universe. Thank you!
Want to become a project sponsor, add your (company) name to the hall of fame and support the developers?