I'm working on a project and I'm trying to create a countdown timer, in days, taking today's time and putting it in a MySQL database, and in 30 days it will run a function.
The documentation on os.time() is confusing, but essentially I want to find a way to get os.difftime() to return the difference between two times in days, so I can check if they are > 30.
Does anyone know how this would be done?
try
[code]print((Time1-Time2)/86400)[/code]
Simple use the unix time, 30 days equals 30*24*60*60
[QUOTE=Wizard of Ass;37667324]Simple use the unix time, 30 days equals 30*24*60*60[/QUOTE]
so if I set it to save os.time() at one instance, and then 30 days later this code is ran
[lua]
if ((os.time() - time)*86400 > 30 then return true end[/lua]
it would return true?
time - os.time() >= 86400
[QUOTE=skar;37667342]so if I set it to save os.time() at one instance, and then 30 days later this code is ran
[lua]
if ((os.time() - time)*86400 > 30 then return true end[/lua]
it would return true?[/QUOTE]
What is the variable 'time'?
[lua]
local EndDate = (os.time() + 86400) --Current time(in seconds) plus one month(in seconds).
[/lua]
Just put the EndDate variable in your database. If you want to check if it is past or still before that date in time just find the difference.
[lua]
if os.time() > EndDate then
--30 days has passed.
else
--It hasn't been 30 days yet.
local TimeLeft = ( EndDate - os.time() ) --This will tell you how much time(in seconds) is left.
local TimePassed = ( 86400 - TimeLeft ) --This is how much time has passed.
end
[/lua]
[QUOTE=Wizard of Ass;37667454]time - os.time() >= 86400[/QUOTE]
time is the date it starts, so why would i do time - os.time()?
wouldn't that give me a negative?
math.Round can take a second argument for the number of digits after the decimal point
Eg, math.Round( 1.1234, 2 ) will round to 1.12
[QUOTE=my_hat_stinks;37678080]math.Round can take a second argument for the number of digits after the decimal point
Eg, math.Round( 1.1234, 2 ) will round to 1.12[/QUOTE]
Ooh I didn't know that, The reason why I did it that way is because I had a project in Java where I was debugging the position of something, and the method in java doesn't have a second argument.
You can also probably tell I'm used to other languages, since I use semi-colons and always use brackets around everything. (Also the 't_' prefix to my variables stands for Temporary, because I didn't like the way "tVariable" or "Variable" looked as a variable name.)
Sorry, you need to Log In to post a reply to this thread.