Determining If a Date and Time is within Working Hours

Written by Allen Wyatt (last updated January 24, 2022)
This tip applies to Excel 2007, 2010, 2013, and 2016


9

Ken has a date and time stored in cell C3. He needs a formula to determine if this date and time is within normal working hours (8 am to 5 pm, Monday through Friday). Ken can easily check the time, but can't figure out a way to check whether it is on a workday.

There are a multitude of formulas you could come up with to solve this situation. The key components of any formula are that you determine if the date is within the range of Monday through Friday (which Ken says he knows how to do) and determine if the time is in the range of 8 am to 5 pm. Once you determine these two facts, you can use the AND function to determine an overall "true" or "false" condition.

As an example, you could use the following formula to determine if the date is in the range of Monday through Friday:

=WEEKDAY(C3, 2) < 6

This returns either True or False and works because the second parameter of the WEEKDAY function, when set to 2, indicates that WEEKDAY return a value of 1 through 7 where 1=Monday and 7=Sunday. Thus, WEEKDAY would return 1, 2, 3, 4, or 5 for the range of Monday through Friday.

For the time portion of the formula, you could use the the HOUR function, in this manner:

=HOUR(C3) >= 8

This returns True or False depending on whether the hour is greater than or equal to 8:00 am. You can test, similarly, if the hour is before 5:00 pm in this way:

=HOUR(C3) <= 17

With these three tests figured out, you can combine them all using the AND function:

=AND(WEEKDAY(C3, 2) < 6, HOUR(C3) >= 8, HOUR(C3) <= 17)

Since the HOUR function returns an integer value (0 through 23), you could shorten the formula even further in this manner:

=AND(WEEKDAY(C3, 2) < 6, HOUR(C3) > 7, HOUR(C3) < 18)

If all three conditions are met, then the AND function returns True. Thus, you could wrap this formula inside of an IF statement, like this:

=IF(AND(WEEKDAY(C3, 2) < 6, HOUR(C3) > 7, HOUR(C3) < 18), "Working", "Non-Working")

This works great, unless you want to start taking holidays into account or your workweek is different than Monday through Friday. In that case, you only need to modify the first part of the formula; the part that uses the WEEKDAY function. My suggestion would be to rely, instead, on either the NETWORKDAYS or NETWORKDAYS.INTL functions. Rather than describe here how to use those functions, you'll want to refer to the ExcelTip entitled "Calculating Business Days."

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (4270) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Copying Worksheets in a Macro

Copying worksheets (one or many) is easy to do manually. What is not well known is that it is even easy to make the ...

Discover More

Creating the 'Mils' Symbol

Different industries use their own terminologies and symbols. In the military, one symbol is referred to as the "mils" ...

Discover More

Freezing Worksheet Tabs

If you have a lot of worksheets in a workbook, you may wonder if you can "freeze" the position of some of those worksheet ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Automatically Entering a Data Entry Time

Excel worksheets can be used to keep track of all sorts of information. You may want to use it, for instance, to track ...

Discover More

Entering Large Time Values

If you need to input humongous times into a worksheet, you may run into a problem if you need to enter times greater than ...

Discover More

Entering or Importing Times without Colons

Enter a time into a cell and you normally include a colon between the hours and minutes. If you want to skip that pesky ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2022-11-24 16:26:46

Michael Monita

Just came across this - how would I set this up if our hours are 9-9 Monday and Tuesday, 9-6 Wednesday to Saturday (closed Sunday).


2020-08-08 19:34:57

Mina Bangal

How about move it from 8 am to 8:01?


2020-05-04 20:14:40

Phil

Thank you so much for this!
Helped work out my SLA's as I was pulling my hair out finding a simple query to tell me if it was in or out of hours!

thanks again from Mel, Australia


2017-08-26 09:06:18

Alex B

This will work too. Sadly the 2 calculations are calculating to a different no of decimals (around E-12), so I had to add a fraction that equates to < 1 sec to make it work.

=IF(AND(WEEKDAY(C3, 2) < 6, HOUR(C3) > 7,(C3-TRUNC(C3))<=(17/24+0.0000001)), "WORKING", "NON WORKING")


2017-08-25 05:46:38

Harold Druss

You're right Fred. I never considered seconds.
"IF(AND(HOUR(C3)=17, MINUTE(C3)=0)" does not look at seconds
but "IF(AND(HOUR(C3)=17, MINUTE(C3)=0, SECOND(C3=0)" fixes it.
Thanks for your insight


2017-08-24 04:00:11

Fred van der Meulen

With your formula you still get the wrong result when you enter a time from 17:00:01 to 17:00:59

The following formula gives the right result:

=IF(AND(WEEKDAY(C3,2)<6,(HOUR(C3)+(MINUTE(C3)/60)+(SECOND(C3)/3600))>=8,(HOUR(C3)+(MINUTE(C3)/60)+(SECOND(C3)/3600))<=17),"WORKTIME","NO WORKTIME")


2017-08-21 04:25:11

Harold Druss

My fix includes 5:00pm but not 5:01pm or later.
HOUR(C3) < 17 does not include 5:00pm.


2017-08-20 21:47:36

Erik

I think the more correct fix to Alex's last equation is to simply change the 18 to a 17:
=IF(AND(WEEKDAY(C3, 2) < 6, HOUR(C3) > 7, HOUR(C3) < 17) , "WORKING", "NON WORKING")

Your fix indicates that one must work one full minute past 5:00 pm (until 17:01), which some might find odd.


2017-08-19 11:09:37

Harold Druss

The formula above gives a false positive if the time is between 5:01pm and 5:59pm
Here is a corrected version:
=IF(AND(WEEKDAY(C3, 2) < 6, HOUR(C3) > 7, HOUR(C3) < 17), "WORKING", IF(AND(HOUR(C3)=17, MINUTE(C3)=0), "WORKING", "NON WORKING"))


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.