Is there a way to check if a variable is a Date in JavaScript?

Kyle Hotchkiss picture Kyle Hotchkiss · May 14, 2010 · Viewed 62.5k times · Source

I was wondering if there is any way to check if an object is specifically a Date in JavaScript. isType returns object for Date, which isn't enough for this scenario. Any ideas? Thanks!

Answer

BrunoLM picture BrunoLM · May 14, 2010

Use instanceof

(myvar instanceof Date) // returns true or false