Can I compare between this 2 dates or do I need to convert one of them?
date1: 2019-07-31T23:00:00
date2: Fri Aug 30 2019 00:00:00 GMT+0100 (heure normale d’Afrique de l’Ouest)
I'm working with Angular
Without using a 3rd party library, you can create new Date objects using both those formats and then simply use > comparer to compare them, like this:
const date1 = new Date("2019-07-31T23:00:00").getTime();
const date2 = new Date("Fri Aug 30 2019 00:00:00 GMT+0100").getTime();
if (this.date1 > this.date2) {
//...
}
If you create a method,
compareDate(dateTimeOne: Date, dateTimeTwo: Date): YouReturn {
if(dateTimeOne.getTime() > dateTimeTwo.getTime()) {
....
}
}
If the variables are not date, you can try something like this
compareDate(dateTimeOne: string, dateTimeTwo: string): YouReturn {
if(Date.parse(dateTimeOne) > Date.parse(dateTimeTwo)) {
....
}
}
You can too try this in moment js..
moment(Date1).format("YYYY-MM-DD") > moment(Date2).format("YYYY-MM-DD")