Questions tagged [date-fns]

date-fns is a JavaScript date/time library that provides a comprehensive, simple and consistent toolset for manipulating JavaScript dates in a browser and Node.js.

date-fns provides a comprehensive, simple and consistent toolset for manipulating JavaScript dates in a browser and Node.js.

date-fns supports both Flow and TypeScript and it works well with module bundlers such as webpack, Browserify, or Rollup and also supports tree-shaking.

Features:

date-fns helps:

  • showing JavaScript dates in a given format
  • checking if a date isAfter or isBefore another
  • adding or removing units of time (addHours, subHours, addMinutes, subMinutes etc)

and it offers other functionalities listed in the documentation.

Example:

Represent a given date in middle-endian format:

var result = format(
  new Date(2014, 1, 11),
  'MM/DD/YYYY'
)
//=> '02/11/2014'

Resources:

496 questions
-1
votes
1 answer

Date-fns Unexpected results when adding months

I am using date-fns for the first time in my project. I need to give user the ability to add a month to current date. I'm wondering how is this supposed to work with different length months? I tried different months with 30 and 31 days and I cannot…
sayayin
  • 971
  • 5
  • 23
  • 36
-1
votes
2 answers

How to convert a date from one type to another typescript

React with Typescript: I have a date picker(mui v5) that requires date value to be in format "yyyy-MM-dd". However the api return a type Date on the format "2022-01-12T00:00:00.000+00:00" Attention: There are many answers to create a string in that…
Raissa Correia
  • 169
  • 4
  • 18
-1
votes
1 answer

Divide timespan in JavaScript

I have to recreate some logic from Kusto query language in JS and I'm struggling with duration division. How can I get quotient from two durations, like this : One can divide two timespan values to get their quotient. For example, 1d / 5h gives 4.8.…
Valium
  • 29
  • 8
-1
votes
2 answers

Format Time Date-FNS

I have a time that I want to convert to a regular time like 08:00:01 PM. data.time = "18:54:00" format(new Date(data.time), `hh:mm:ss A`)
Joseph
  • 7,042
  • 23
  • 83
  • 181
-1
votes
1 answer

Why is my json date string Invalid for date-fns?

I know this has been asked before. But reviewing those answers I can't figure it out. I have a Json date string docdate: "2020-10-02T00:00:00" that I am trying to convert to a date for display. I use System.Text.Json to serialize it in the API. I am…
Randy
  • 1,137
  • 16
  • 49
-1
votes
1 answer

Convert date from mm/yyyy to mm/yy using either date-fns or moment

I have a string representing a expiry date coming through in format mm/yyyy ie 01/2021 representing January 2021. Would it possible to convert the date string mm/yy using either date-fns or moment? I can't access date-fns documentation as their site…
physicsboy
  • 5,656
  • 17
  • 70
  • 119
-1
votes
2 answers

try catch doesn't get date-fns parseISO error

there seems a simple mistake by me, I wrote this code to get a formatted date but if date dosn't have correct string to convert, class should catch the error but it doesn't work and an error is shown in console ! import {format,parseISO} from…
Hamid Shoja
  • 3,838
  • 4
  • 30
  • 45
-2
votes
1 answer

Functional/ES6 way to detect differences between date intervals?

I have a function that I am using to try and determine if a set of date segments meets a criteria. I am using date-fns' distanceInDays function to return an integer value of the distance between the previous segment's end date and the current…
Luke Martin
  • 109
  • 7
-2
votes
1 answer

how do I write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050

Please how do I write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050 using date fns library.
-2
votes
1 answer

How to displays name of days of week

I'm starting react and I follow a tutorial for make a calendar with date-fns, but the version of date-fns in the tutorial is different to my version. I meet a problem to display the name of the days week. Code of tutorial (old version of date-fns)…
PtiCassarin
  • 3
  • 1
  • 3
-2
votes
1 answer

Date-fns is being received as null value on the backend

Frontend: React Backend: SpringBoot Date format on the BE: 2011-10-05T14:48:00.000Z I've tried to use the date-fns to send the correct format from the FE to the BE application, ut even following the documentation, the BE is receiving null. Salvar…
-2
votes
4 answers

Parse time '1hr 30m 4s' as time ahead in JavaScript

Let's say I have a string 1hr 30m 4s. How would I use Node.js to parse that string into (obviously) a time in the future from the date it was executed? I have looked at the NPM packages date-fns and moment but they do not seem to cater to what I am…
Green Mtn
  • 447
  • 4
  • 8
-3
votes
2 answers

Convert date with timezone to UTC?

A quick question. I have a ISO string date: 2022-07-03T10:51:09+02:00 this date as you can see has timezone included (+02:00). Question: How to convert it into UTC date? Using e.g. date-fns or moment? Edit: Should I just simply add "02:00" hours to…
underfrankenwood
  • 431
  • 1
  • 7
  • 22
-3
votes
1 answer

Timezone independent dates javascript

Using javascript/react native + redux i need to save timestamps in a time format that is aware of local time when saving the date, but unaware when reading the same date in another timezone. Take a hypothetical user that travels west around the…
Simon
  • 621
  • 4
  • 21
-4
votes
2 answers

Formatting 2021-12-26T00:00:00.000000Z in date-fns | reactjs

How can I format this date to a simple one? I am using date-fns as in my react project 2021-12-26T00:00:00.000000Z
Gurupal singh
  • 136
  • 1
  • 3
  • 10
1 2 3
33
34