What is the best way to determine if a date is today in JavaScript?
You could use toDateString
:
var d = new Date()
var bool = (d.toDateString() === otherDate.toDateString());
The answers based on toDateString()
will work I think, but I personally would avoid them since they basically ask the wrong question.
Here is a simple implementation:
function areSameDate(d1, d2) {
return d1.getFullYear() == d2.getFullYear()
&& d1.getMonth() == d2.getMonth()
&& d1.getDate() == d2.getDate();
}
MDN has a decent overview of the JS Date object API if this isn't quite what you need.