Socket
Socket
Sign inDemoInstall

date-fns

Package Overview
Dependencies
0
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    date-fns

Date helpers


Version published
Maintainers
1
Install size
29.0 kB
Created

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

Changelog

Source

[0.8.0] - 2014-10-09

Changed

  • Internal: reuse addDays inside of subDays.

Added

  • addMonths

  • subMonths

  • setMonth

  • setYear

Readme

Source

date-fns

Date helpers in function-per-file style.

API

Code is fully documented, checkout source for reference.

  • isWeekend - is passed date is weekend?
  • isToday - is passed date is today?
  • startOfDay - returns start of a day for passed date
  • endOfDay - returns end of a day for passed date
  • startOfWeek - returns start of a week for passed date
  • endOfWeek - returns end of a week for passed date
  • startOfMonth - returns start of a month for passed date
  • endOfMonth - returns end of a month for passed date
  • eachDay - returns array of dates within specified range
  • addDays - add specified number of days to passed date
  • subDays - substract specified number of days from passed date
  • addMonths - add specified number of months to passed date
  • subMonths - substract specified number of days from passed date
  • isSameWeek - returns true if passed dates belongs to the same week
  • isSameMonth - returns true if passed dates has same month (and year)
  • isFirstDayOfMonth - return true if passed date is first day of month
  • isLastDayOfMonth - return true if passed date is last day of month
  • setMonth - sets month index
  • setYear - sets full year

FAQs

Last updated on 09 Oct 2014

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc