I'm trying to validate that a certain endDate is after a startDate. I've tried everything I found and could think of but nothing works. Some examples of what I've tried:
check('endDate').isAfter(new Date('startDate')).withMessage('End date of lab must be valid and after start date')
check('endDate').isAfter(new Date('startDate').toDateString()).withMessage('End date of lab must be valid and after start date')
check('endDate').isAfter('startDate').withMessage('End date of lab must be valid and after start date')
check('endDate').isAfter(new Date('' + 'startDate').toDateString()).withMessage('End date of lab must be valid and after start date')
The docs say that isAfter() expects a string.
If both
startDateandendDateare input fields, you should use a custom validator in order to have access to both values:If
startDate, is a predefined value, you can use theisAftervalidator, for exampleThen you can check the dates you want