Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

# Create IF + between hours

Best Answer Exaskryz , 09 October 2015 - 01:29 AM

6 replies to this topic
• Members
• 180 posts
• Last active: Jan 03 2018 02:49 AM
• Joined: 25 Sep 2014

Hi,

```If ((A_Hour=12) && (A_Min>=25) && (A_Min<=30))
Msgbox 12:25 - 12:30```

The above code works fine. But I am having trouble creating between hours for 12:30 - 15:05.

I tried a few combination but dont work properly. Below is the code I work on so far.

`If ((A_Hour>=12) && (A_Min>30) || (A_Hour=15) && (A_Min<=5))`

Please help. Thanks.

• Spam Officer
• 3219 posts
• Last active: Sep 20 2018 02:47 PM
• Joined: 19 Apr 2005

an example

```a=1740
b=1741

stringmid,c,a_now,9,4
if (b>c and c>=a)
msgbox, 262208,Between %a%-%b% , It is between %a% and %b%`nTIME_NOW=%c%,
else
msgbox, 262208,Between %a%-%b% , NOT between %a% and %b%`nTIME_NOW=%c%,
return
esc::exitapp

```

• Members
• 3249 posts
• Last active: Nov 20 2015 05:30 AM
• Joined: 23 Aug 2012
If ((A_Hour>=12) && (A_Min>30) || (A_Hour=15) && (A_Min<=5))

This can be tricky. Notice that you are accepting if the time is 18:35, where 18>=12 and 35>30, so it must be true.

I would break it up into three blocks. A portion of the first hour, a portion of the last hour, and all the hours in between.

```If (((A_Hour=12 && A_Min>30)) || ((A_Hour>12) && (A_Hour<15)) || ((A_Hour=15) && (A_Min<=5)))
MsgBox The time is after 12:30 but before or exactly 15:05.

```

That first block makes sure that the hour is 12. If so, it must be past 30 minutes into the hour.

The second block makes sure that the hour is 13 or 14. If so, the minutes don't matter.

The third block makes sure that the hour is 15. If so, it must be within the first 6 minutes (00, 01, 02, 03, 04, and 05) of the hour.

If all three evaluate to false, then the MsgBox will not appear.

• Members
• 180 posts
• Last active: Jan 03 2018 02:49 AM
• Joined: 25 Sep 2014

Thank you Garry.

Exaskryz,

Just to confirm if I understand this.

After 12:30 to 15:00.

`If (((A_Hour=12 && (A_Min>30)) || ((A_Hour>12) && (A_Hour<15)) || (A_Hour=15))`

After 12:30 to before 15:00

`If (((A_Hour=12 && (A_Min>30)) || ((A_Hour>12) && (A_Hour<15)))`

11:55 to before 12:00

```If (((A_Hour=11) && (A_Min>=55)) || ((A_Hour=11) && (A_Hour<12)))
```

• Members
• 3249 posts
• Last active: Nov 20 2015 05:30 AM
• Joined: 23 Aug 2012
✓  Best Answer

Your first example is close, but not quite right. You have three expressions in there, the first two being correct. But the last expression will hold true for any time between 15:00 and 15:59. You would want to include ` && (A_Min=0)` for that.

The second example is correct. I take it from your wording being different from example 1 you did not want to include 15:00, so what you have done is right.

The third example is wrong. I don't think you meant to put that second expression as so, as you are evaluating A_Hour's value twice. Your first expression here covers times 11:55-11:59, which based on your word description, would be all you need. I would omit the second expression. However, if you wanted to include 12:00, it would be like the first example's last expression. You would see if A_Hour=12, and also that A_Min=0. As you have it right now, that second expression is going to evaluate true whenever A_Hour=11, so all together that line will be true from times 11:00 to 11:59.

• Members
• 249 posts
• Last active: May 26 2017 04:13 AM
• Joined: 18 Feb 2015

Just suggesting another approach here (though it's not completely tested).

```formattime, hourvar, , h   ; hour w/o leading zero
formattime, minvar, , mm    ; min w/ leading zero
ctime:=hourvar . minvar

if (ctime>=1230) and (ctime<=1505)
Msgbox, BOOM!

return
```

• Members
• 180 posts
• Last active: Jan 03 2018 02:49 AM
• Joined: 25 Sep 2014

Thank you lilygel.

Thank you Exaskryz for your good explanation. Wish you good day.