Check if a value is a valid date string

By Hunter Becton on January 22, 2023

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.