Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript check if it has passed midnight since a certain time

I need to create a javascript function that checks if it has been a day since timeX (an instance of Date). I do NOT mean whether is has been 24 hours since timeX, but instead whether it has passed a midnight since timeX.

I am a PHP expert, not a JavaScript one, so I was wondering if anyone here had any quick answers. Thanks!

function(dateLast, dateNow) {...}
like image 323
Jonah Avatar asked Feb 27 '23 04:02

Jonah


1 Answers

A simple solution to check whether two dates represent the same day is:

function isSameDay(a, b) {
    return a.toDateString() == b.toDateString();
}

This works no matter what the distance between the two dates is.

like image 79
Max Shawabkeh Avatar answered Mar 01 '23 18:03

Max Shawabkeh