I am about the compare two dates in JavaScript with each other
for example consider this two value :
date1 = 2024-5-13T20:30:00
date2 = 2024-5-13T21:30:20
the day and month is the same but the hours is different
my goal is to return true for each day that have the same value as month and year and …
its should compare the date in the format yyyy/mm/dd
the method I used first time :
date1.toISOString().split('T')[0] === date2.toISOString().split('T')[0]
this method is not suitable for me because its loop between the characters of time string then split and its reduce the performance
3
Answers
Cut time in UTC:
Cut time in local timezone:
Let’s benchmark:
Using toLocaleDateString is a short way to check this, however Intl.DateTimeFormat is faster:
Try this code. If you have any problem further, feel free to reach out me.