angularangular-moment

Angular: Exclude time in Date comparison


Here this.startDate.value is Sun Aug 30 2020 05:30:00 GMT+0530 (India Standard Time) and this.endDate.value is Sun Aug 30 2020 00:00:00 GMT+0530 (India Standard Time). Since the time is different, comparison is working in this case.

if (moment(this.startDate.value).isAfter(moment(this.endDate.value,'day'))) {
    //
} 

Is there any way to exclude time with this above comparison.


Solution

  • Worked below code:

    if (moment(this.startDate.value.format('YYYY-MM-DD')).isAfter(moment(this.endDate.value).format('YYYY-MM-DD'))) {
        //..
    }