IF Activity Condition for Time Range Check

Hi,

I need a condition for an “IF” activity. The logic is: if the current time is between 1:25 AM and 2:30 AM, the condition should go to the “Else” section.

I used the below conditions but not working

  1. (DateTime.ParseExact(CurrentDate, “HHmmss”, CultureInfo.InvariantCulture).TimeOfDay >= New TimeSpan(11, 10, 0)) AndAlso (DateTime.ParseExact(CurrentDate, “HHmmss”, CultureInfo.InvariantCulture).TimeOfDay <= New TimeSpan(12, 10, 0))

  2. Now.Hour >= 11 AndAlso Now.Hour <= 12 AndAlso Now.Minute >= 10 AndAlso Now.Minute <= 15

Any help is appreciated. Thanks in advance!

Hi @jai_kumar2

Not (Now.TimeOfDay >= New TimeSpan(1, 25, 0) AndAlso Now.TimeOfDay <= New TimeSpan(2, 30, 0))

As Current Time is not between the specified,It moved to the Then block

Hope it helps!!

Hi @pravallikapaluri, Thanks for the reply.

However, the current time is not 1:25 AM, correct? Therefore, the condition should go to the “else” section. Please correct me if I’m mistaken.

@jai_kumar2

If the current time is between 1:25 and 2:30 AM,it executes the else block.
If not it executes the then block.

@jai_kumar2

If you want the code should executes in a reverse remove Not in the If condition

the current time is not 1:25 AM.Therefore, the condition should go to the “else” section.
Use the below condition.

(Now.TimeOfDay >= New TimeSpan(1, 25, 0) AndAlso Now.TimeOfDay <= New TimeSpan(2, 30, 0))
1 Like

Now I am getting the expected result

Thank you.

@jai_kumar2

You’re Welcome.

Happy Automation.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.