The isValid
function from date-fns library is used to check if a given date is valid or not. It returns a boolean value indicating if the date is valid or not.
Here is an example demonstrating how to use isValid
function:
index.tsx237 chars8 lines
In the above example, we first import isValid
function from the date-fns library. We then create a valid date object date
with the date of 30th October 2021. When we pass this date to isValid
function, it returns true.
Next, we create an invalid date object invalidDate
by passing an invalid string to the Date
constructor. When we pass this date to isValid
function, it returns false.
gistlibby LogSnag