Search code examples
if-statementgoogle-sheetstimenested-ififs

Google Sheets: Determining if a time falls within a two specified times


I'm trying to find a way to determine if a time falls between two specific times - with two different scenarios to flag. So far, I'm coming up empty (and frustrated!)

Column B has date/times such as:

February 9, 2022 09:55AM
February 9, 2022 01:15PM
February 9, 2022 09:39PM

Flag 1: Time is between 4AM and Noon

Flag 2: Time is between 8PM and 4AM -- does this need to be broken down into two separate conditions given that it spreads over midnight?

Resulting Output in Column C:

FLAG 1
[Blank Cell - No Flag]
FLAG 2

Appreciate any ideas - thanks to the community, as always.

CTO


Solution

  • try:

    =ARRAYFORMULA(IFERROR(IF(
     (TIMEVALUE(A1:A)>=TIMEVALUE("4:00:00"))*
     (TIMEVALUE(A1:A)< TIMEVALUE("12:00:00")), "Flag 1",IF(
     (TIMEVALUE(A1:A)>=TIMEVALUE("20:00:00"))*
     (TIMEVALUE(A1:A)<=TIMEVALUE("23:59:59"))+
     (TIMEVALUE(A1:A)>=TIMEVALUE("00:00:00"))*
     (TIMEVALUE(A1:A)< TIMEVALUE("04:00:00")), "Flag 2", ))))
    

    enter image description here