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!
You can use the ! isNaN() function to check whether a date is valid. If x is a Date, isNaN(x) is equivalent to Number.
To check if a date is after another date, compare the Date objects, e.g. date1 > date2 . If the comparison returns true , then the first date is after the second, otherwise the first date is equal to or comes before the second.
Using the Date. One way to check if a string is date string with JavaScript is to use the Date. parse method. Date. parse returns a timestamp in milliseconds if the string is a valid date.
Use instanceof
(myvar instanceof Date) // returns true or false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With