I'm trying to validate a user input for a datetime using date-fns:
import { isDate, isValid } from 'date-fns';
console.log('DATE:', stringVal);
console.log('IS_DATE:', isDate(new Date(stringVal)));
console.log('IS_VALID:', isValid(new Date(stringVal)));
This produces:
DATE: 2023-02-31 03:03:03
IS_DATE: true
IS_VALID: true
This seems to be incorrect because February 31, 2023 is not a valid date. What is the correct way of validating an ISO date string?
Looks like I can use the
parseISO
function: