Counting Hours in a Schedule

mike4777

Board Regular
Joined
Apr 12, 2011
Messages
122
I was wondering if someone could help me develop a formula to count the hours when formatted in such a way:

NameHoursMondayTuesdayWednesdayThursday
Name 1=Formula8am-8pm10:30pm-6:15ametcetc
Name 2
Name 3
etc

<tbody>
</tbody>

I can do it with a million LEft( and Right( but that seems terribly clunky and prone to possible error.
 
Last edited:
If you're not entering a date with each time, can you assume it will not be over 24 hours in a single shift? If so you must specify an end date with the end time, otherwise there is no way to interpret the logic.

In the case of 12pm as a start time and 8pm as an end time, subtraction indeed will work. F2-D2. End time minus start time. But if you do have hours which go past midnight, you'll need to use the date. Or at the very least assume that the date is always one day later for anything over midnight.

You don't need AM/PM in the cell [time] values, but if you don't use them you'll need to use military time. For example 5:00 PM would be 17:00. Thus 8:00 PM would be 20:00, or 20 hours, and 12:00 PM would be 12:00, or 12 hours, and 20-12 = 8. To use AM/PM correctly and not as text, you'll need a space between the time value. For example, 8:00AM is text, where as 8:00 AM is a time value.

If you assume one entry is always less than 24 hours, start times in column D, end times in column F, data starting in row 2, you could use simply...

Code:
=IF(F2<=D2,1,0)+F2-D2
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Here is what I have so far.

=((SUM(VALUE(IF(FIND(":", D3,1)=2, LEFT(D3,1), LEFT(D3,2))), IF(LEFT(RIGHT(D3,4),2)="15",0.25,IF(LEFT(RIGHT(D3,4),2)="30",0.5,IF(LEFT(RIGHT(D3,4),2)="45",0.75,IF(LEFT(RIGHT(D3,4),2)="00",0, "")))))) - (SUM(VALUE(IF(FIND(":",F3,1)=2, LEFT(F3,1), LEFT(F3,2))), IF(LEFT(RIGHT(F3,4),2)="15",0.25,IF(LEFT(RIGHT(F3,4),2)="30",0.5,IF(LEFT(RIGHT(F3,4),2)="45",0.75,IF(LEFT(RIGHT(F3,4),2)="00",0, "")))))))

This isolates the numbers and subtracts them.
But again,
12pm - 8pm does not equal 4 hours
 
Upvote 0
you need to put manually a space in between the number and "PM" e.g. 12 pm or use substitute function
<colgroup><col width="173" style="width: 130pt; mso-width-source: userset; mso-width-alt: 6326;"> <col width="110" style="width: 83pt;"> <col width="185" style="width: 139pt; mso-width-source: userset; mso-width-alt: 6765;"> <col width="179" style="width: 134pt; mso-width-source: userset; mso-width-alt: 6546;"> <col width="110" style="width: 83pt;"> <tbody> </tbody>
 
Upvote 0
If you're not entering a date with each time, can you assume it will not be over 24 hours in a single shift? If so you must specify an end date with the end time, otherwise there is no way to interpret the logic.

In the case of 12pm as a start time and 8pm as an end time, subtraction indeed will work. F2-D2. End time minus start time. But if you do have hours which go past midnight, you'll need to use the date. Or at the very least assume that the date is always one day later for anything over midnight.

You don't need AM/PM in the cell [time] values, but if you don't use them you'll need to use military time. For example 5:00 PM would be 17:00. Thus 8:00 PM would be 20:00, or 20 hours, and 12:00 PM would be 12:00, or 12 hours, and 20-12 = 8. To use AM/PM correctly and not as text, you'll need a space between the time value. For example, 8:00AM is text, where as 8:00 AM is a time value.

If you assume one entry is always less than 24 hours, start times in column D, end times in column F, data starting in row 2, you could use simply...

Code:
=IF(F2<=D2,1,0)+F2-D2


I didn't know that about the 8:00 pm (with a space). Interesting. But when I put that format in excel converts it to a number format which defeats the purpose of a schedule (unless there is some way to have it keep the "12:00 pm" format).

The dates are not programmed in there but that is an easy fix. I'll put that on row 2. Shifts will indeed go from 11pm - 7am so the date will have to be used as you say. I'm not sure how to do that.
 
Upvote 0
Try=mod(f2-d2,1)
For the graveyard shift use =mod(end time- start time,1)
<colgroup><col width="173" style="width: 130pt; mso-width-source: userset; mso-width-alt: 6326;"> <col width="110" style="width: 83pt;"> <col width="185" style="width: 139pt; mso-width-source: userset; mso-width-alt: 6765;"> <col width="179" style="width: 134pt; mso-width-source: userset; mso-width-alt: 6546;"> <col width="110" style="width: 83pt;" span="3"> <tbody> </tbody>
 
Upvote 0
what are these supposed to do and where do these go? The schedule still has the numeric values on it. (just so you know, the time boxes are drop down menu).
 
Upvote 0
I gave you the formula. Basically the check logic is this:

If the end date is smaller than the start date, add a day, then subtract, otherwise just subtract the end time from the start time.

The cell format you want for the input cells is this (select the desired cells, then press CTRL+1):
h:mm AM/PM

For the output cell, you don't want AM/PM, and you want hours to accumulate, so the format would need to be:
[h]:mm
 
Upvote 0
this is not working. Somehow the value goes ############# when I type in 12:00am (it is formatted as you say).
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,348
Members
449,097
Latest member
thnirmitha

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