Skip to content

Tag: date-fns

UTC issue on formatting date

I have this react typescript/js code: but it’s not working properly. It changes fromDate to the next day when I run it late at night. So I tried on 6/30/2022 at 11pm and it changed it to 7/1/2022. My attempted fix is to use date-fns format function: My question is will this resolve the utc issue? Maybe …

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 make sense of it. If I add a month to July

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. This gives one the ability to express any timespan val…

How to use date-fns in a Node.js project?

I installed date-fns as per the following instruction on https://www.npmjs.com/package/date-fns After that my package.json is updated with the following entry: Then, I wrote the following code from https://date-fns.org/ and it resulted in error: Error: node -v: Answer I managed to run it successfully by using…

Date-fns is returning incorrect dates

I have a collection of date strings stored in a database in this format: 2018-06-28T14:06:26.524Z 2018-07-02T10:32:18.818Z 2018-07-06T15:08:50.233Z I need to convert these dates into a format like this on the frontend: 28 June 2018 14:06:26 02 July 2018 10:32:18 06 July 2018 08:50:23 My attempt at doing this …