Whether an event was within working hours

jlaff

New Member
Joined
Aug 26, 2024
Messages
2
Office Version
  1. 2021
Platform
  1. MacOS
Hi, I am trying to determine whether an event happened withing working hours (Mon-Fri, 9am - 5pm). I am only interested in the initial time presentation (it is research looking at when patients with heart attacks presented to hospital). I have all of their dates and times of presentations below - I just want to know if the time of presentation was 'in-hours' or 'out-of-hours'. I will manually edit out the public holidays afterwards but I have 7k patients so am looking for a formula. Any help much appreciated!
 

Attachments

  • Screenshot 2024-08-26 at 14.40.28.png
    Screenshot 2024-08-26 at 14.40.28.png
    139.2 KB · Views: 5

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe
Excel Formula:
=IF(AND(WEEKDAY(EM2, 2) < 6, HOUR(EM2) >= 9, HOUR(EM2) < 17),"in-hours","out-of-hours")

Edited because had the wrong column 🙄
 
Last edited:
Upvote 0
Welcome to the Board!

For a date/time in cell EM2, try this formula:
Excel Formula:
=IF(OR(WEEKDAY(EM2,3)>4,MOD(EM2,1)<(9/24),MOD(EM2,1)>(17/24)),"Off hours","")
If will return "Off hours" for any weekend date, or any time before 9:00 AM or after 5:00 PM.
 
Upvote 0
Mark/ Joe, thank you guys so much!

I have spent hours trawl;ing google trying to find how to do this You guys are great! Really appreciate it!
 
Upvote 0
You are welcome.
Glad we could help!

If you analyze them, you will see that Mark and I use the same underlying logic, but a little different functionality. That is one of the great things about Excel, there are often many different ways to accomplish the same thing. Mark's use of the HOUR function is probably a little simpler (and more intuitive) than using the MOD function. Had I seen his answer before I posted, I probably wouldn't have posted my solution.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,497
Messages
6,160,152
Members
451,625
Latest member
sukhman

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