Monday, June 3, 2024
48
rated 0 times [  55] [ 7]  / answers: 1 / hits: 32577  / 7 Years ago, wed, november 29, 2017, 12:00:00

I am getting datetime from an API call like following-:



2017-11-21T20:23:26+0000



Now I want to compare this with today's date and calculate the difference in number of days, how can i do that in google apps script.



thank you for your help.


More From » google-apps-script

 Answers
3

i think you can do something like this,



var dt1 = new Date(), // today's date
dt2 = new Date(2017-11-21T20:23:26+0000); // your date from API

// get milliseconds
var t1 = dt1.getTime(),
t2 = dt2.getTime();

var diffInDays = Math.floor((t1-t2)/(24*3600*1000));
// 24*3600*1000 is milliseconds in a day
console.log(diffInDays);

[#55809] Sunday, November 26, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;