Languages
[Edit]
EN

JavaScript - test if variable is date type

3 points
Created by:
Niac
478

In this short article, we would like to show how to check if the variable is date type.

Quick solution:

// ONLINE-RUNNER:browser;

function isDate(value) {
    return value instanceof Date;
}

// Usage example:

var value1 = '2020-07-02';
var value2 = new Date();
var value3 = Date.now();

console.log(isDate(value1)); // false
console.log(isDate(value2)); // true
console.log(isDate(value3)); // false

Note: read this article to know how to check variable type.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join