0

How to subtract from
year:2026 month:JAN day:26 - year:2025 month:NOV day:27 in JavaScript

My firstDate: year:2026 month:JAN day:26
My second date: year:2025 month:NOV day:27

So how can I find the difference between these two dates in JavaScript?

I was expecting to subtract them by using getTime() but it’s returning Invalid Date

Or another word is there another way to subtract dates in non UTC format?

If not how can I convert those dates to UTC format?

Note: I’m receiving those dates from API response and both dates are String

14
  • @MisterJojo where is the timezone? If there is no time, calculate in absolute days: jsfiddle.net/mplungjan/mqy2b4gx Commented Dec 28, 2023 at 14:48
  • this calculation is distorted if the 2 dates are different summer/winter daytimes. Commented Dec 28, 2023 at 14:54
  • no timezone on both dates Commented Dec 28, 2023 at 14:56
  • The only thing I need is to find the difference between those dates to ensure that difference is 30 days but how can I calculate in absolute days? Thanks! Commented Dec 28, 2023 at 15:01
  • Actually I don't have to create a UTC date. The only reason I wanted to convert to UTC is to make calculation between the dates. If I can make a calculation without converting to UTC, that's fine. Sorry I'm very new to JavaScript! Commented Dec 28, 2023 at 15:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.