EN
JavaScript - test if variable is date type
3 points
In this short article, we would like to show how to check if the variable is date type.
Quick solution:
xxxxxxxxxx
1
function isDate(value) {
2
return value instanceof Date;
3
}
4
5
// Usage example:
6
7
var value1 = '2020-07-02';
8
var value2 = new Date();
9
var value3 = Date.now();
10
11
console.log(isDate(value1)); // false
12
console.log(isDate(value2)); // true
13
console.log(isDate(value3)); // false
Note: read this article to know how to check variable type.