Socket
Socket
Sign inDemoInstall

date-fns

Package Overview
Dependencies
0
Maintainers
3
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    date-fns

Modern JavaScript date utility library


Version published
Weekly downloads
17M
decreased by-13.31%
Maintainers
3
Created
Weekly downloads
 

Package description

What is date-fns?

The date-fns npm package provides a comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js. It offers a variety of functions to parse, validate, manipulate, and format dates.

What are date-fns's main functionalities?

Parsing Dates

Parse strings in ISO format to JavaScript Date objects.

const parseISO = require('date-fns/parseISO');
const result = parseISO('2023-04-12');

Formatting Dates

Format Date objects into strings with a given format.

const format = require('date-fns/format');
const result = format(new Date(2023, 3, 12), 'yyyy-MM-dd');

Comparing Dates

Compare two dates to determine if one comes before the other.

const isBefore = require('date-fns/isBefore');
const result = isBefore(new Date(2023, 3, 12), new Date(2023, 3, 13));

Manipulating Dates

Perform date calculations such as adding or subtracting time spans.

const addDays = require('date-fns/addDays');
const result = addDays(new Date(2023, 3, 12), 10);

Validating Dates

Check if a date is valid.

const isValid = require('date-fns/isValid');
const result = isValid(new Date('2023-04-12'));

Other packages similar to date-fns

Readme

Source

date-fns

Build Status Docs Status

Date helpers in the function-per-file style.

Installation

npm

npm install date-fns --save

Bower

bower install date-fns

Usage

var isLastDayOfMonth = require('date-fns/is_last_day_of_month')
var date = new Date(2014, 1, 28)
console.log(isLastDayOfMonth(date))
//=> true

API

Code is fully documented, check the source for the reference.

Common helpers

  • format - format the date.
  • isFuture - is the given date in the future?
  • isPast - is the given date in the past?
  • isEqual - are the given dates equal?
  • isBefore - is the first date before the second one?
  • isAfter - is the first date after the second one?
  • compareAsc - compare the two dates and return -1, 0 or 1.
  • compareDesc - compare the two dates reverse chronologically and return -1, 0 or 1.
  • max - return the latest of the given dates.
  • min - return the earliest of the given dates.
  • closestTo - return a date from the array closest to the given date.
  • parse - parse the ISO-8601-formatted date.
  • isValid - is the given date valid?
  • isValidDateValues - is the date constructed from the given values exist?
  • distanceInWords - return the distance between the given dates in words.
  • distanceInWordsToNow - return the distance between the given date and now in words.

Range helpers

Milliseconds helpers

Seconds helpers

Minutes helpers

Hours helpers

Day helpers

Weekday helpers

Week helpers

  • startOfWeek - return the start of a week for the given date.
  • endOfWeek - return the end of a week for the given date.
  • lastDayOfWeek - return the last day of a week for the given date.
  • addWeeks - add specified number of weeks to the given date.
  • subWeeks - subtract specified number of weeks from the given date.
  • differenceInWeeks - get the number of full weeks between the given dates.
  • differenceInCalendarWeeks - get the number of calendar weeks between the given dates.
  • isSameWeek - are the given dates in the same week?
  • isThisWeek - is the given date in the same week as the current date?

ISO week helpers

Month helpers

Quarter helpers

Year helpers

  • getYear - get the year.
  • setYear - set the year.
  • startOfYear - return the start of a year for the given date.
  • endOfYear - return the end of a year for the given date.
  • lastDayOfYear - return the last day of a year for the given date.
  • addYears - add the specified number of years to the given date.
  • subYears - subtract the specified number of years from the given date.
  • differenceInYears - get the number of full years between the given dates.
  • differenceInCalendarYears - get the number of calendar years between the given dates.
  • isSameYear - are the given dates in the same year?
  • isThisYear - is the given date in the same year as the current date?
  • isLeapYear - is the given date in the leap year?
  • getDaysInYear - get the number of days in a year of the given date.

ISO week-numbering year helpers

  • getISOYear - get the ISO week-numbering year.
  • setISOYear - set the ISO week-numbering year.
  • startOfISOYear - return the start of an ISO week-numbering year for the given date.
  • endOfISOYear - return the end of an ISO week-numbering year for the given date.
  • lastDayOfISOYear - return the last day of an ISO week-numbering year for the given date.
  • addISOYears - add the specified number of ISO week-numbering years to the given date.
  • subISOYears - subtract the specified number of ISO week-numbering years from the given date.
  • differenceInISOYears - get the number of full ISO week-numbering years between the given dates.
  • differenceInCalendarISOYears - get the number of calendar ISO week-numbering years between the given dates.
  • isSameISOYear - are the given dates in the same ISO week-numbering year?
  • isThisISOYear - is the given date in the same ISO week-numbering year as the current date?
  • getISOWeeksInYear - get the number of weeks in the ISO week-numbering year.

I18n

TODO

Tests

Kudos to SauceLabs for the provided Automate API. Thereby we run cross-browser tests on every push!

FAQs

Last updated on 28 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc