How to check if Date/Time falls into a period? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rc76
Posts: 153
Joined: 07 Nov 2020, 01:45

How to check if Date/Time falls into a period?

18 Jan 2024, 20:56

Hi,

If I wish to check if current workday and time falls within a specified period, than do xxx, how may I achieve that?

for example:

if (DayOfWeek = Mon, Tue, Wed) and (Time is between "1400 and 1600")
{
; than do xxx
}

I tried the following code but I think I am doing something wrong...

Code: Select all

FormatTime, currentTime_day, , ddd
FormatTime, currentTime, , HH:mm
FormatTime, currentTime_s, , HH:mm:ss

if (currentTime_day = "Mon" or currentTime_day = "Tue" or currentTime_day = "Wed") 
    and 
    (currentTime > "14:00" and currentTime < "16:00")
{
    ; than do xxx
}
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: How to check if Date/Time falls into a period?  Topic is solved

18 Jan 2024, 21:29

Try:

Code: Select all

FormatTime, currentTime_day, , ddd
FormatTime, currentTime, , HHmm

if (currentTime_day ~= "Wed|Thu|Fri" and currentTime > "1800" and currentTime <= "1900")
	msgbox "Yeah!"
else
	msgbox "Nope"
This: currentTime > "14:00" does not work as "14:00" is just a string. You need an integer (or a float).
14.3 & 1.3.7
rc76
Posts: 153
Joined: 07 Nov 2020, 01:45

Re: How to check if Date/Time falls into a period?

18 Jan 2024, 22:20

Awesome! Thank you so much flyingDman!
rc76
Posts: 153
Joined: 07 Nov 2020, 01:45

Re: How to check if Date/Time falls into a period?

20 Jan 2024, 02:38

it seems the | operator not working in the if statement:

if (Operation_Current = "Restarting_AppOn|Restarting_AppOff") ---> Not working

if (Operation_Current = "Restarting_AppOn" or Operation_Current = "Restarting_AppOff") ---> working
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to check if Date/Time falls into a period?

20 Jan 2024, 04:15

rc76 wrote: if (Operation_Current = "Restarting_AppOn" or Operation_Current = "Restarting_AppOff") ---> working
That's why
if (Operation_Current = "Restarting_AppOn" | Operation_Current = "Restarting_AppOff")
also works. ;)

:idea: -> Operators must not be part of strings!
rc76
Posts: 153
Joined: 07 Nov 2020, 01:45

Re: How to check if Date/Time falls into a period?

20 Jan 2024, 04:26

haha got it. thank you so much Just Me!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], peter_ahk and 385 guests