This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Next day (os.date)
#1
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.?
Reply
#2
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)
Reply
#3
This is brilliant.

Thank you so much!
Reply
#4
Why not using ?:
Code:
date = os.date('*t', os.time() + 86400)
log(date)
Reply
#5
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.
Reply


Forum Jump: