aquí está mi código, estoy tratando de forzar que los dos campos de fecha sean siempre diferentes, la fecha de finalización debe ser al menos 1 día después de la fecha de inicio.
const EditSchema = Yup.object().shape({ StartDate: Yup.date() .transform(value => (isDate(value) ? undefined : value)) .typeError('Enter a start date') .required('Enter a start date'), EndDate: Yup.date() .min(Yup.ref('StartDate'), 'End date must be after start date') .transform(value => (isDate(value) ? undefined : value)) .typeError('Enter an end date') .required('Enter an end date') });Después de horas tratando de averiguar cómo hacerlo.
aquí está el código.
cuando tiene un selector de fecha y selecciona una fecha, será algo como esto "01/01/2021 00:00:00".
Entonces, si necesita que la fecha de finalización sea al menos 1 día después de la fecha de inicio, debe agregar 1 hora a la fecha de inicio, lo que no le permitirá poner 2 fechas iguales.
StartDate: Yup.date() .transform(value => (isDate(value) ? undefined : value)) .typeError('Enter a date') .required('Enter a date') ), EndDate: Yup.date() .min(Yup.ref('StartDate'), 'End date must be after start date') .when('StartDate', (st, schema) => { if(st != null){ st.setHours(st.getHours() + 1); return schema.min(st) //this else prevents your page from crashing if there's any other input }else return schema.min('1900-01-01') }) .transform(value => (isDate(value) ? undefined : value)) .typeError('Enter a date') .required('Enter a date') });