I was doing calculation on two dates. I need to find how much days left for the user to use their contract in the site. I have expiry date stored in the DB. And I need to compare this with the current date and get the remaining days left to enjoy their subscription.
Initially this number of days remaining calculation was in the C#.
var daysLeft = Convert.ToInt32((data.expiryDate.Date - DateTime.Now.Date).TotalDays);
//Say, the expiryDate is Thu Dec 31 2020 00:00:00 GMT+0530 (India Standard Time), And daysLeft is 220 for the above statement
And Now i tried the same in Moment.js in client side.
moment(data.expiryDate).diff(moment(), 'days')
//Say, the expiryDate is Thu Dec 31 2020 00:00:00 GMT+0530 (India Standard Time) and it is giving 219.
I also tried like subtracting two dates in same format after converting it to YYYY-DD-MM as below which is giving the error
moment(data.expiryDate).format('YYYY-DD-MM').diff(moment().format('YYYY-DD-MM'), 'days')
Object doesn't support property or method 'diff'
Why in C# its 220 and in moment.js it is 219? Am I missing anything? Please suggest me where the calculation goes wrong.