Home > Software engineering >  Can't get the days difference in momentJs
Can't get the days difference in momentJs

Time:11-28

I'm trying to get how many days left till the date, I'm using momentJs, below is the code I'm using but in front end it gives me Nan which means error.

const start = moment();
  const end = moment(coupon.validTill, 'DD MM YYYY');
  const diff = end.diff(start, "days")

coupon.validTill is 30/02/2023 The image below is from my collection in mongodb which shows the validity date

enter image description here

CodePudding user response:

your validTill date is wrong, fab month can't have 30 days. use a valid date and try, it will work fine.

  • Related