'AWS Lambda difference in days should be 3, getting 19097

I have a AWS lambda function, part of which computes the difference between a previous date and todays date, adjusts to represent as days and then finally rounds this to the nearest number, so 12.8 days for example will be 13.

I'm wondering if anyone knows if Lambda has some different way of representing Date() functions, because upon logging the results of various steps in the process I'm getting some weird values returned and hence my function isn't working. Here's some code:

const today = new Date();
let item = {lasetReceiptCreated: '2022-04-11T20:00:22.549Z'};

let lastReceiptCreated = new Date(item.lasetReceiptCreated);
let dateDiff = today.getTime(); - lastReceiptCreated.getTime();
let diffInDays = Math.round(dateDiff / (1000 * 3600 * 24));

console.log('SkipDayCalc: ','\ndiff: ',diffInDays,'\ntoday.getTime: ',today.getTime(),'\nreceipt.getTime(): ',lastReceiptCreated.getTime());

The resulting log shows this:

SkipDayCalc:  
diff:  19097 
today.getTime:  1649963123100 
receipt.getTime():  1649707222549

So why is my diffInDays value returning as 19097? When I run in a node sandbox I'm getting the correct value with the same exact code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source