Comparing date in software development is a common and require in most of the applications. This blog provides you snapshot of sample code to compare the date in Angular application.

Sample code:

isExpired: boolean = false;

private async checkEventExpiry() {
    var dateToday = formatDate(new Date(), 'MMM  d, yyyy hh: mm', 'en_US');
    var eventDate = formatDate(this.event.eventStartDate, 'MMM  d, yyyy hh:mm', 'en_US');
   //here this.event.eventStartDate is your actual date that need to compare
    if (dateToday > eventDate) {
      this.isExpired = true;
    }
  }

Leave a Reply

Your email address will not be published. Required fields are marked *