Excel test to see if time falls between two times spanning midnight.

Maggie Barr

Board Regular
Joined
Jan 28, 2014
Messages
188
Greetings, and thank you in advance if you can help.
I am on a PC using Microsoft Office Pro 2019 desktop.
I need to test if a time falls between two times that span midnight. It is for testing if protocol was followed for surveys. So the time survey conducted should be between the evening of one day and pre sunrise the next. I have a table of times (see below), and I need to test the survey time in one row by the start and end times in the same row. I have tried +IF(AND formulas, but it just doesn't work, and everything I find online is for set start and end times, not cell referenced, and they do not pan midnight. I even tried using the time values (HA), and of course that didn't work. I have almost 5,000 of these to check, possibly more, and it will continue next year, so it would be great to be able to automate this in some way.
Any guidance would be greatly appreciated, and thank you in advance if you can help.
Best Wishes,
Maggie

Survey timeStartEnd
21:27​
20:2504:47
21:37​
20:2504:47
21:47​
20:2504:47
21:57​
20:2504:47
22:07​
20:2504:47
22:17​
20:2504:47
22:27​
20:2504:47
22:37​
20:2504:47
22:47​
20:2504:47
22:57​
20:2504:47
21:33​
20:3404:41
21:43​
20:3404:41
21:53​
20:3404:41
22:03​
20:3404:41
22:13​
20:3404:41
22:23​
20:3404:41
22:33​
20:3404:41
22:43​
20:3404:41
22:53​
20:3404:41
23:03​
20:3404:41
21:27​
20:2804:44
21:37​
20:2804:44
21:47​
20:2804:44
21:57​
20:2804:44
22:07​
20:2804:44
22:17​
20:2804:44
22:27​
20:2804:44
22:37​
20:2804:44
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,

You didn't explain what or how you want your results.
Assuming the Time values in the 3 Columns do Not include Date values, may be this:

Book3.xlsx
ABCD
1Survey timeStartEndCompliance
221:2720:254:47TRUE
322:2720:254:47TRUE
423:2720:254:47TRUE
522:0720:254:47TRUE
623:0720:254:47TRUE
721:2720:254:47TRUE
822:2720:254:47TRUE
923:2720:254:47TRUE
1022:0720:254:47TRUE
1123:0720:254:47TRUE
1221:2720:344:41TRUE
1322:2720:344:41TRUE
1423:2720:344:41TRUE
1522:0720:344:41TRUE
1623:0720:344:41TRUE
1721:2720:344:41TRUE
1822:2720:344:41TRUE
1923:2720:344:41TRUE
2022:0720:344:41TRUE
2123:0720:344:41TRUE
2217:0720:284:44FALSE
2318:2720:284:44FALSE
2419:2720:284:44FALSE
2520:2720:284:44FALSE
2621:2720:284:44TRUE
2722:2720:284:44TRUE
2823:2720:284:44TRUE
2922:2720:284:44TRUE
Sheet1046
Cell Formulas
RangeFormula
D2:D29D2=AND(A2>B2,A2<C2+24)
 
Upvote 0
jtakw,
Thank you for reaching out and providing information. I thought at firs it was working, but when I went through the data to search for FLASE results, any Survey time after midnight had FALSE despite that it was still less than the end protocol time. Survey time of 00:13 and Protocol of 20:41 start and 04:44 end came back as false.
Any further advice?
Thank you again for your efforts!
Maggie
 
Upvote 0
Maybe this:

=OR(A2>=B2,A2<=C2)
steve the fish,
Thank you for reaching out! I thought for sure that it had to be an AND in order to function properly because I need it to be between the two times, but I ran your formula and it appears to be working. I can't wrap my brain around why, but it must be that the OR is acceptable because it can be viewed as two separate tests, greater than or equal to the start time to midnight, OR less than or equal to the end time, and since the time spans across midnight, it actually functions fine. I wonder if the time span was within a single day if it would still work. I'll have to play around and find out just so I know.
Either way, it appears to be working, and I will modify it to a IF(OR so I can customize the text in response to the test and add the <= and >=.
Thank you so much! Love the name by the way!
Best Wishes,
Maggie
 
Upvote 0
jtakw,
Just an update that the OR formula that steve the fish provided worked. I thought it had to be an AND formula, but apparently not.
I wanted to thank you for your efforts though, I appreciate it.
Maggie
 
Upvote 0
jtakw,
Just an update that the OR formula that steve the fish provided worked. I thought it had to be an AND formula, but apparently not.
I wanted to thank you for your efforts though, I appreciate it.
Maggie

You're welcome.

I Pointed that out in my Post #5 above.
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top