Current Day vs Selected Day

No problem, thanks for your help!

1 Like

The calculation of the number of days is wong.
For January and February, it will not count the days and will only add up the year and the month, this is why the outcome of assignment date and current date will be 2053 (2022 + 31 “number of days in January”) ignoring the number of days and therefore it will always be “Due today”


This functions is the one failing

1 Like

Alright, thanks for pointing this out. How could I resolve this?

1 Like

Hello @jakeheron
in one of the applications I needed a similar feature. I used the services of this site: Calculate Duration Between Two Dates – Results
as after the comparison I save in the data table the color in which I want it to be colored. The DV element reads from the table what its color is.

2 Likes

You need to change the blocks in the red rectangle.

Here is an example. Creates a task and marks a color according to the time after which it should be completed. I have marked 3 intervals <= 3, <= 7 and others. Respectively colors red, green and white. There is an option to change the current day to check how the expiration dates have already changed and mark them again. Of course, the blocks can be optimized a lot, but I only had 10 minutes. I hope it helps you!

https://x.thunkable.com/copy/1355f045775192fd57cf84ca96c8fe2b

2 Likes

It would be easier to use Google sheet with 3 columns (Start Date, End Date, Duration). You can update Start Date and End Date and then just read Duration.

1 Like

Yes, definitely @muneer !
Here is another simple method for calculating elapsed days from a certain date.


My English is not very good and I may not have properly understood the case under discussion. Please excuse me if I’m just spamming!

2 Likes

This is the standard way in all languages and even in Excel and Google sheets. Dates are actually stored as numbers similar to Unix timestamp.

However, there is not an easy way in Thunkable to convert from standard date to timestamp.

I use JavaScript and Web Viewer to do the conversion but sometimes this becomes a big job for a small feature.

1 Like

Dates can be taken directly from the Date Input block (for visualization), and the proposed method only counts days. Therefore, it does not need to be converted back to date.

1 Like

Let me show you what I mean. I created a quick JavaScript file and changed the project you shared to produce the difference between any two days, even if they are a year apart. Not that the time is given in local time and the original Date is in GMT

https://x.thunkable.com/projectPage/62065661baff3d00106f9ffb

Choose any start day and end day then click Show Duration. Enjoy.

1 Like

Thank you so much, it is working now. I will keep this thread open in case I run into any further issues.

Thanks for all your help once again!

regards,

Jake.

1 Like

Marking it as solved does not close the post. You can still comment on it. Anyway, there was nothing wrong in the code. It just need to treat the condition in a better way.

1 Like