Skip to content
Advertisement

How to compare two different date formats in javascript

Hi all I am new to date time things in javascript. I am facing one issue while comparing two different date formats. Objective- I want to compare date/time coming from the backend with the current time. If time coming from backend is past time I need to do some other stuff or if it is in future I want to do something else.

Issue- Current date format is something like this – Mon Jan 10 2022 16:38:58 GMT+0530 (India Standard Time) Date Time getting from backend is like – 2022-01-03T18:30:00Z

Code –

JavaScript

Output – Meeting is in future

Issue – Using this code I am getting meetings in future, but all the meeting time is actually past time. How can I resolve this issue?

Advertisement

Answer

new Date will take either format.

JavaScript

If you want difference in days, hours etc, you will need more code easily found at SO

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement