Hello,
Question is in the title - how can I get yesterday’s date with os.date()?
I’d like to be able to get this and be able to store/print the value as yyyy/m/d
Hello,
Question is in the title - how can I get yesterday’s date with os.date()?
I’d like to be able to get this and be able to store/print the value as yyyy/m/d
To get yesterdays date you can use this:
os.date("%x", os.time()-86400)
Edit: Here is your formatted version
print(string.format("%s/%s/%s", os.date("%Y", os.time()-86400), os.date("%m", os.time()-86400), os.date("%d", os.time()-86400)))
You should only have to call the function once, then do all the formatting later.
local date = os.date("!*t", os.time() - 86400)
local fs = "%i/%02i/%02i"
print(string.format(fs, date.year, date.month, date.day))