Logic Machine Forum
Compare times - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Compare times (/showthread.php?tid=2605)



Compare times - camillsg - 22.04.2020

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 


RE: Compare times - benanderson_475 - 22.04.2020

(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



RE: Compare times - admin - 22.04.2020

See this: https://forum.logicmachine.net/showthread.php?tid=2443&pid=15434#pid15434


RE: Compare times - camillsg - 22.04.2020

(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!!