Check if a value is a valid date string
JavaScript code snippet that makes sure a value is a valid date string for creating a Date object.
const isDateString = (value) => !isNaN(Date.parse(value));
How it works
There are several ways to create a Date object with JavaScript. Because of this flexibility, you may want to check if the value being passed in is valid. This code snippet will return true
or false
depending if the value passed in creates a valid date object.