Days until a date

fbarajas

New member
Hi! How can I obtain the days till some day? For example, I want to assign how many days to some event (or to the end of the year) in a variable. How can I do that? Is there a way to substract dates?

Thanks!
 

FrameXX

Well-known member
I think the best way to get this difference is to convert both dates into unix timestamps (seconds since 1970-1-1 00:00) then substract the earlier date from the later date and then divide by 86400 (seconds in 1 day). You can get current unix timestamp with system_time magic text, but you can't get unix timestamp of any date easily with MacroDroid. You could try to calculate it manually and even make it into an action block (which is what I have tryed), but the actual calculation isn't that easy because of all that leap years, different count of day in month etc...(AFAIK most languages have built-in function to get unix timestamp or vice versa.) Maybe someone will do better, but I am urging @MacroDroidDev to add a simple to/out timestamp convertion action.

EDIT: You can simply use shell comands to get unix timestamps and vice versa.

Get unix timestamp:
Bash:
date -d '2022-12-3 18:38:00' +%s

Get date:
Bash:
date -d @1670089080

You use -ud to get UTC date:
Bash:
date -ud @1670089080

Action blocks I just made may help you with the conversion:
 
Last edited:

Jacob L

Moderator (Lawsonator)
Hi! How can I obtain the days till some day? For example, I want to assign how many days to some event (or to the end of the year) in a variable. How can I do that? Is there a way to substract dates?

Thanks!
Search the MacroDroid store for 5691
 
Top