I am trying to compare two dates in a VueJs application. I need to show whether the selected date is higher / not than today's date.
I applied separate functionalities to get today's date and the selected date. Both return the date in dd-mm-yyyy format.
When I compare those two dates using,
if (dateEntered < currentDate) {
}
it is not working. How do I compare the two dates?
In this case, moment
come in handy. Like below
var date1 = moment(dateEntered).format("dd-mm-yyyy")
var date2 = moment(currentDate).format("dd-mm-yyyy")
if(date1 > date2){
//Do your thing
} else {
}
You need to install moment
and import it import moment from "moment"