Lua: changing Date table to string or some other format
I have looked through many pages that tell me how date and time work in lua but have not found a solution. Basically I want to take the current date and time and then add 1 month to that date and then store that new date in my MySQL table in a format that I can later compare to the current day of that time. For example:if now > oldDate then do something
I managed to get the current date / time as a table and add 1 month to it by doing the following:
local t = os.date( "*t" )
t.month = t.month + 1
But I couldn't figure out how to turn it into some kind of DateTime format that I can store in MySQL and then compare.
Any help would be appreciated!
source to share
Lua os.date
accepts an optional time parameter as second argument
> local t = os.date("*t")
> t.month = t.month + 1
> print(os.date("%Y-%m-%d", os.time(t))
2014-12-16
The row can then be inserted as a date into a MySQL table.
To compare two dates in Lua compare the output os.time()
if os.time() > os.time(t) then
print("The time has come.")
end
source to share