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.

Compare times
#1
Hi! 

I want to check if the local time is "greater" than a specific time, regardless of date.
As an example I want to check if the clock is more than 19 o'clock. 
Is there a simple way to do this? Maybe with just two lines of scripting?

I understand that os.time(os.date('*t')) returns local time as the number of seconds from Thursday, 1 January 1970.
And os.time({year=2001, month=9, day=11, hour=13, minute=46}) returns also the number of seconds from Thursday, 1 January 1970.

But what I really want is os.time({hour=13, minute=46}), which I do not think is possible to write. 
And I want to see if this time is before or later the local time os.date('*t'), but just hour and minutes.

Thanks for all your help!! 
Kind regards,
Camilla 
Reply
#2
(22.04.2020, 10:19)camillsg Wrote: Hi! 

I want to check if the local time is "greater" than a specific time, regardless of date.
As an example I want to check if the clock is more than 19 o'clock. 
Is there a simple way to do this? Maybe with just two lines of scripting?

I understand that os.time(os.date('*t')) returns local time as the number of seconds from Thursday, 1 January 1970.
And os.time({year=2001, month=9, day=11, hour=13, minute=46}) returns also the number of seconds from Thursday, 1 January 1970.

But what I really want is os.time({hour=13, minute=46}), which I do not think is possible to write. 
And I want to see if this time is before or later the local time os.date('*t'), but just hour and minutes.

Thanks for all your help!! 
Kind regards,
Camilla 

you can do it like this 

Code:
local t = os.date("*t")

if t.hour == 13 and t.min == 46 then 
--do something
end

-- if hour is greater than or equal to 13.00
if t.hour >=13 then
--do something else
end
Reply
#3
See this: https://forum.logicmachine.net/showthrea...4#pid15434
Reply
#4
(22.04.2020, 10:30)benanderson_475 Wrote:
(22.04.2020, 10:19)camillsg Wrote: Hi! 

I want to check if the local time is "greater" than a specific time, regardless of date.
As an example I want to check if the clock is more than 19 o'clock. 
Is there a simple way to do this? Maybe with just two lines of scripting?

I understand that os.time(os.date('*t')) returns local time as the number of seconds from Thursday, 1 January 1970.
And os.time({year=2001, month=9, day=11, hour=13, minute=46}) returns also the number of seconds from Thursday, 1 January 1970.

But what I really want is os.time({hour=13, minute=46}), which I do not think is possible to write. 
And I want to see if this time is before or later the local time os.date('*t'), but just hour and minutes.

Thanks for all your help!! 
Kind regards,
Camilla 

you can do it like this 

Code:
local t = os.date("*t")

if t.hour == 13 and t.min == 46 then 
--do something
end

-- if hour is greater than or equal to 13.00
if t.hour >=13 then
--do something else
end


Thank you so much!!
Reply


Forum Jump: