I am trying to validate date using Yup validation. The requirement is that the ToDate
should be greater or equal to the fromDate
.
fromDate
: ‘2022-02-13T16:31:13.983Z’
toDate
: ‘2023-02-01T00:00:00.000Z’
REQUIREMENT
- toDate >= fromDate
fromDate: Yup.string().required('required.'),
toDate: Yup.string().required('required')
.test(
"fromDate",
"To Date should be greater or equal to From Date",
(date) => moment().isAfter(moment(date), 'hours')
),
But it seems the logic is quite wrong. . I’d appreciate your help. Thanks.