Finding number of days between two dates

I’m trying to find the number between two dates. I tried to remake this JS code in Thunkable:

const startDate  = '2020-01-01';
const endDate    = '2020-03-15';

const diffInMs   = new Date(endDate) - new Date(startDate)
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);

console.log(diffInDays)

I tried to get the milliseconds between the two dates by subtracting them and then dividing them 8640000 to turn them back to # of days. but got stuck when i try to get the new Date value.

Here are the blocks so far:

I’ve been unsuccessful, has anyone found a way to easily do this?

1 Like

Yeah, even I have this same question. Also, how do you find the date a certain number of days after a specified date?
For example, I want to find 14 days after 26 February. How do I do that?
Also, I want to check if a given date is 14 days after another certain date. For example, I want to check if 19 July(let’s say that the user inputted that date) is 14 days after 29 June, and display a message based on whether it is or isn’t.
Any ideas on how to do this?
Thanks

2 Likes

:supervillain:🏻‍♂

You guys need to use a webviewer and JavaScript. That’s it!

3 Likes

Thanks. How do you post dates the user has inputted? I know a little JS but this is quite above my level.

I would send all data as a JSONobject in the webviewer and work with it as such

1 Like

Do I do this using the same code that @p.powercoders1i0t has given in his code?