Home > other >  how to make calculation of days based on 2 dates using angular12
how to make calculation of days based on 2 dates using angular12

Time:12-02

i am using angular12, here calculation of days based on 2 dates works fine with chrome, but the same thing fails in firefox.

TS: Using Moment, gives invalid date error under firefox:

 getDaysCount(firstDate: any, secondDate: any) {
    let first = moment(firstDate, 'MM-DD-YYYY');
    let second = moment(secondDate, 'MM-DD-YYYY');
    return second.diff(first, 'days');
  }

console.log(this.getDaysCount('11-12-2022', '11-14-2022));

var Difference_In_Days = Math.ceil(Math.abs(secondDate - firstDate) / (1000 * 60 * 60 * 24));

this gives NAN in firefox but gives 2 in chrome.

CodePudding user response:

Take a look at this enter image description here

Chrome console:

enter image description here

  • Related