How to check if the current hour is among two hours?

Hello
I want to check if the current hour (for example 2 PM) is among two hours (for example 1 PM and 9 PM). In this case the output would be TRUE.

Thanks

Hi @EngAnalyst

Check this string var as time difference
Timedifference = DiffHours.TotalHours.ToString) and set the condition as Timedifference < 2. here the value of time difference is 5.33XXX

Or int value1=(datevalue1-datevalue2).total hours<2

Thanks
Ashwin.S

thanks for the reply.

Let’s say i want to get the value True if the current hour is between 1:00 AM and 7:00 AM.

  • example 1: current hour is 4:02 AM -> true
  • example 2: current hour is 6:10 AM -> true
  • exmaple 3: current hour is 9:43 AM -> false
    how can i check that?

AshwinS2

Time to string, split the string in two numbers (hour and minute) and check them in one IF statement.
Or use a RegEx: /([1-6]:\d{2})|7:00) AM/

1 Like

Hi @EngAnalyst

Have a try of using condition like

Datetime.parseexact(“value1”,“dd/mm/yyyy hh:mm:as”, System.globalization.InvariantCulture).equals(Datetime.now.addhours().toString()

Or @Palaniyappan
Any suggestions

Thanks
Ashwin.S

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