Unsure what I am doing wrong with my dates together with moment.js.
I have the following code:
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))
}
The output of my console.log for both startDate and endDate is:
SE 15/08/2021 19/08/2021
For some reason though, when calling this function, it is saying that my:
End date must be greater than or equal to start date
which based on my return moment(startDate).isSameOrBefore(moment(endDate)), should not be the case as end date 19/08/2021 is after start date 15/08/2021
What am I missing?
Compare the original dates, not the formatted dates, since moment.js doesn't know that they're in DD/MM/YYYY format.
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))
}