No estoy seguro de lo que estoy haciendo mal con mis fechas junto con moment.js.
Tengo el siguiente código:
function(value) { const startDate = moment(this.parent.startDate).format("DD/MM/YYYY") const endDate = moment(value).format("DD/MM/YYYY") console.log("SE",startDate,endDate) return moment(startDate).isSameOrBefore(moment(endDate)) } El resultado de mi console.log para startDate y endDate es:
SE 15/08/2021 19/08/2021
Sin embargo, por alguna razón, al llamar a esta función, está diciendo que mi:
End date must be greater than or equal to start date
que, según mi return moment(startDate).isSameOrBefore(moment(endDate)) , no debería ser el caso, ya que la fecha de finalización 19/08/2021 es posterior a la fecha de inicio 15/08/2021
¿Qué me estoy perdiendo?
Compare las fechas originales, no las fechas formateadas, ya que moment.js no sabe que están en formato DD/MM/YYYY .
function(value) { const startDate = moment(this.parent.startDate).format("DD/MM/YYYY") const endDate = moment(value).format("DD/MM/YYYY") console.log("SE",startDate,endDate) return moment(this.parent.startDate).isSameOrBefore(moment(value)) }