How to compare time strings? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 236
Joined: 10 Mar 2016, 21:19

How to compare time strings?

15 Mar 2019, 07:23

Hello.
With this code, I can get the current time every 10m:

Code: Select all

SetTimer, GetCompTime, 600000
return

GetCompTime:
FormatTime, MyTime,, HH:mm:ss tt
ToolTip % MyTime
return
Let's say I want to create a task which runs only once every day between 00:00:00 am and 00:10:00 am in the morning,
My problem is how do I make the comparison of this type:

Code: Select all

if current time is between time1 and time2, do the task only once
I have searched the old posts for this subject, some of them involve the EnvSub command or they change the format again with FormatTime. But they all also use the date in the comparison. I only want to compare the time since the task will repeat daily and not on a specific day.
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: How to compare time strings?  Topic is solved

15 Mar 2019, 09:14

if (Round(A_Hour)=0) && (Round(A_Min)<=10)

:?:
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: How to compare time strings?

15 Mar 2019, 10:41

@sinkfaze
It looks like you used Round in purpose
Can I know the reason why ?
I guess, it would work well without it
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: How to compare time strings?

15 Mar 2019, 10:44

Since those variables can output numbers with leading zeroes, and the OP is looking for hour "00" anyway, I want to be sure that the comparison sees them as numbers and not strings. Maybe not necessary, but it's assurance for me.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: How to compare time strings?

15 Mar 2019, 10:52

thanks
before I post the above question, I have tested

Code: Select all

If(00 = 0)
	MsgBox Yes
Else
	MsgBox No
Regards
KilliK
Posts: 236
Joined: 10 Mar 2016, 21:19

Re: How to compare time strings?

15 Mar 2019, 17:49

Thank you for the help, I ll test it asap.
thanks again.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Google [Bot], Melchisedek, mikeyww, NicolaLearnsAHK, songdg, tatermakes and 61 guests