Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  33] [ 3]  / answers: 1 / hits: 37625  / 13 Years ago, tue, december 6, 2011, 12:00:00

I have a date object in JavaScript and I want to figure out if that date is today. What is the fastest way of doing this?



My concern was around comparing date object as one might have a different time than another but any time on today's date should return true.


More From » jquery

 Answers
28

You could use toDateString:



var d = new Date()
var bool = (d.toDateString() === otherDate.toDateString());

[#88736] Sunday, December 4, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;