Logic Machine Forum
Next day (os.date) - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Next day (os.date) (/showthread.php?tid=3940)



Next day (os.date) - FatMax - 21.03.2022

I need something to happen the next day retrieved from the os.date function. 

How do I get the correct value in the easiest fashion, correcting for month change, etc.?


RE: Next day (os.date) - admin - 21.03.2022

You can simply add +1 to day number, convert to timestamp, then get a date from that timestamp. It handles year/month wrap-around automatically.
Code:
date = os.date('*t') -- current date (table)
date.day = date.day + 1 -- add 1 day
time = os.time(date) -- convert to timestamp
date = os.date('*t', time) -- tomorrow date (table) from timestamp
log(date)



RE: Next day (os.date) - FatMax - 21.03.2022

This is brilliant.

Thank you so much!


RE: Next day (os.date) - Erwin van der Zwart - 21.03.2022

Why not using ?:
Code:
date = os.date('*t', os.time() + 86400)
log(date)



RE: Next day (os.date) - admin - 21.03.2022

There's a certain edge case when the time jumps backwards due to the daylight saving time change. But it looks like that date.day + 1 method is also affected by this.