This tutorial focuses on various ways to calculate times in Excel. You will find a few useful formulas to add and subtract times, calculate time difference, or elapsed time, and more.
In the last week's article, we had a close look at the specificities of Excel time format and capabilities of basic time functions. Today, we are going to dive deeper into Excel time calculations and you will learn a few more formulas to efficiently manipulate times in your worksheets.
How to calculate time difference in Excel (elapsed time)
To begin with, let's see how you can quickly calculate elapsed time in Excel, i.e. find the difference between a beginning time and an ending time. And as is often the case, there is more than one formula to perform time calculations. Which one to choose depends on your dataset and exactly what result you are trying to achieve. So, let's run through all methods, one at a time.
Formula 1. Subtract one time from the other
As you probably know, times in Excel are usual decimal numbers formatted to look like times. And because they are numbers, you can add and subtract times just as any other numerical values.
The simplest and most obvious Excel formula to calculate time difference is this:
Depending on you data structure, the actual time difference formula may take various shapes, for example:
Formula | Explanation |
=A2-B2 |
Calculates the difference between the time values in cells A2 and B2. |
=TIMEVALUE("8:30 PM") - TIMEVALUE("6:40 AM") |
Calculates the difference between the specified times. |
=TIME(HOUR(A2), MINUTE(A2), SECOND(A2)) - TIME(HOUR(B2), MINUTE(B2), SECOND(B2)) |
Calculates the time difference between values in cells A2 and B2 ignoring the date difference, when the cells contain both the date and time values. |
Remembering that in the internal Excel system, times are represented by fractional parts of decimal numbers, you are likely to get the results similar to this:
The decimals in column D are perfectly true but not very meaningful. To make them more informative, you can apply custom time formatting with one of the following codes:
Time code | Explanation |
h | Elapsed hours, display as 4. |
h:mm | Elapsed hours and minutes, display as 4:10. |
h:mm:ss | Elapsed hours, minutes and seconds, display as 4:10:20. |
To apply the custom time format, click Ctrl + 1 to open the Format Cells dialog, select Custom from the Category list and type the time codes in the Type box. Please see Creating a custom time format in Excel for the detailed steps.
And now, let's see how our time difference formula and time codes work in real worksheets. With Start times residing in column A and End times in column B, you can copy the following formula in columns C though E:
=$B2-$A2
The elapsed time is displayed differently depending on the time format applied to the column:
Note. If the elapsed time is displayed as hash marks (#####), then either a cell with the formula is not wide enough to fit the time or the result of your time calculations is a negative value.
Formula 2. Calculating time difference with the TEXT function
Another simple technique to calculate the duration between two times in Excel is using the TEXT function:
- Calculate hours between two times:
=TEXT(B2-A2, "h")
- Return hours and minutes between 2 times:
=TEXT(B2-A2, "h:mm")
- Return hours, minutes and seconds between 2 times:
=TEXT(B2-A2, "h:mm:ss")
Notes:
- The value returned by the TEXT function is always text. Please notice the left alignment of text values in columns C:E in the screenshot above. In certain scenarios, this might be a significant limitation because you won't be able to use the returned "text times" in other calculations.
- If the result is a negative number, the TEXT formula returns the #VALUE! error.
Formula 3. Count hours, minutes or seconds between two times
To get the time difference in a single time unit (hours ,minutes or seconds), you can perform the following calculations.
Calculate hours between two times:
To present the difference between two times as a decimal number, use this formula:
Supposing that your start time is in A2 and end time in B2, you can use a simple equation B2-A2 to calculate the difference between two times, and then multiply it by 24, which is the number of hours in one day:
=(B2-A2) * 24
To get the number of complete hours, use the INT function to round the result down to the nearest integer:
=INT((B2-A2) * 24)
Total minutes between two times:
To calculate the minutes between two times, multiply the time difference by 1440, which is the number of minutes in one day (24 hours * 60 minutes = 1440).
As demonstrated in the following screenshot, the formula can return both positive and negative values, the latter occur when the end time is less than the start time, like in row 5:
=(B2-A2)*1440
Total seconds between times:
To get the total seconds between two times, you multiply the time difference by 86400, which is the number of seconds in one day (24 hours * 60 minutes * 60 seconds = 86400).
In our example, the formula is as follows:
=(B2-A2)* 86400
Note. For the results to display correctly, the General format should be applied to the cells with your time difference formula.
Formula 4. Calculate difference in one time unit ignoring others
To find the difference between 2 times in a certain time unit, ignoring the others, use one of the following functions.
- Difference in hours, ignoring minutes and seconds:
=HOUR(B2-A2)
- Difference in minutes, ignoring hours and seconds:
=MINUTE(B2-A2)
- Difference in seconds, ignoring hours and minutes:
=SECOND(B2-A2)
When using Excel's HOUR, MINUTE and SECOND functions, please remember that the result cannot exceed 24 for hours and 60 for minutes and seconds.
Note. If the end time is less than the start time (i.e. the result of the formula is a negative number), the #NUM! error is returned.
Formula 5. Calculate elapsed time from a start time to now
In order to calculate how much time has elapsed since the start time to now, you simply use the NOW function to return today's date and the current time, and then subtract the start date and time from it.
Supposing that the beginning date and time is in call A2, the formula below returns the following results, provided you've applied an appropriate time format to column B, h:mm in this example:
=NOW()-A2
In case the elapsed time exceeds 24 hours, use one of these time formats, for example d "days" h:mm:ss like in the following screenshot:
If your starting points contain only time values without dates, you need to use the TIME function to calculate the elapsed time correctly. For example, the following formula returns the time elapsed since the time value in cell A2 up to now:
=TIME(HOUR(NOW()), MINUTE(NOW()), SECOND(NOW())) - A2
Note. The elapsed time is not updated in real-time, it refreshes only when the workbook is reopened or recalculated. To force the formula to update, press either Shift + F9 to recalculate the active spreadsheet or hit F9 to recalculate all open workbooks.
Formula 5. Display time difference as "XX days, XX hours, XX minutes and XX seconds"
This is probably the most user-friendly formula to calculate time difference in Excel. You use the HOUR, MINUTE and SECOND functions to return corresponding time units and the INT function to compute the difference in days. And then, you concatenate all these functions in a single formula along with the text labels:
=INT(B2-A2) & " days, " & HOUR(B2-A2) & " hours, " & MINUTE(B2-A2) & " minutes and " & SECOND(B2-A2) & " seconds"
To instruct your Excel time difference formula to hide zero values, embed four IF functions into it:
=IF(INT(B2-A2)>0, INT(B2-A2) & " days, ","") & IF(HOUR(B2-A2)>0, HOUR(B2-A2) & " hours, ","") & IF(MINUTE(B2-A2)>0, MINUTE(B2-A2) & " minutes and ","") & IF(SECOND(B2-A2)>0, SECOND(B2-A2) & " seconds","")
The syntax may seem excessively complicated, but it works :)
Alternatively, you can calculate time difference by simply subtracting the start time from the end time (e.g. =B2-A2
), and then apply the following time format to the cell:
d "days," h "hours," m "minutes and" s "seconds"
An advantage of this approach is that your result would be a normal time value that you could use in other time calculations, while the result of the complex formula discussed above is a text value. A drawback is that the custom time format cannot distinguish between zero and non-zero values and ignore the latter. To display the result in other formats, please see How to show time over 24 hours, 60 minutes, 60 seconds.
How to calculate and display negative times in Excel
When calculating the time difference in Excel, you may sometimes get the result as ###### error because the difference is a negative time. But is there a way to show negative times properly in Excel? Of course, there is a way, and even more than one :)
Method 1. Change Excel Date System to 1904 date system
The fastest and easiest way to display negative time normally (with a minus sign) is switching to the 1904 date system. To do this, click File > Options > Advanced, scroll down to the When calculating this workbook section and put a tick in the Use 1904 date system box.
Click OK to save the new settings, and from now on negative times will be displayed correctly, like negative numbers:
Method 2. Calculate negative time in Excel with formulas
Is changing Excel's default Date System is not an option, then you can force negative times to display properly using one of the following formulas:
=IF(A2-B2>0, A2-B2, "-" & TEXT(ABS(A2-B2),"h:mm"))
=IF(A2-B2>0, A2-B2, TEXT(ABS(A2-B2),"-h:mm"))
Both formulas check if the time difference (A2-B2) is greater than 0, and if it is they return that difference. If the time difference is less than zero, the first formula calculates the absolute difference and concatenates the minus sign. The second formula yields exactly the same result by using a negative time format "-h::mm".
Note. Please keep in mind that unlike the first method that treats negative times as negative numeric values, the result of the TEXT function is always a text string that cannot be used in calculations or other formulas.
Adding and subtracting time in Excel
Basically, there are 2 ways to add and subtract time in Excel:
- Using the TIME function
- Using arithmetic calculations based on the number of hours (24), minutes (1440) and seconds (86400) in one day
The TIME(hour, minute, second)
function makes Excel time calculations really easy, however it does not allow adding or subtracting more than 23 hours, or 59 minutes, or 59 seconds. If you are working with bigger time intervals, then use one of the arithmetic calculations demonstrated below.
How to add or subtract hours to time in Excel
To add hours to a given time in Excel, you can use one the following formulas.
TIME function to add under 24 hours
For example, if your start time is in cell A2, and you want to add 2 hours to it, the formula is as follows:
=A2 + TIME(2, 0, 0)
Note. If you try adding more than 23 hours with the TIME function, the specified hours will be divided by 24 and the remainder will be added to the start time value. For example, if you try to add 25 hours to "6/2/2015 10:00 AM" (cell A4) using the formula =A4 + TIME(25, 0, 0)
, the result will be "06/02/2015 11:00", i.e. A4 + 1 hour.
Formula to add any number of hours (under or over 24 hours)
The following formula has no limitations to the number of hours you want to add:
For example, to add 28 hours to the start time in cell A2, enter the following formula:
=A2 + (28/24)
To subtract hours from a given time, you use analogous formulas, and just replace "+" with the minus sign:
For example, to subtract 3 hours from the time in cell A2, either of the following formulas will do:
=A2-(3/24)
=A2-TIME(3,0,0)
To subtract more than 23 hours, use the first one.
How to add / subtract minutes to time in Excel
To add minutes to a given time, employ the same techniques that we've just used for adding hours.
To add or subtract under 60 minutes
Use the TIME function and supply the minutes you want to add or subtract in the second argument:
And here are a couple of real-life formulas to calculate minutes in Excel:
To add 20 minutes to the time in A2: =A2 + TIME(0,20,0)
To subtract 30 minutes from the time in A2: =A2 - TIME(0,30,0)
To add or subtract over 60 minutes
In your calculation, divide the number of minutes by 1440, which is the number of minutes in a day, and add the quotient to the start time:
To subtract minutes from time, simply replace plus with the minus sign. For example:
To add 200 minutes: =A2 + (200/1440)
To subtract 300 minutes: =A2 -(300/1440)
How to add / subtract seconds to a given time
Second calculations in Excel are done in a similar fashion.
To add under 60 seconds to a given time, you can use the TIME function:
To add more than 59 seconds, use the following formula:
To subtract seconds, utilize the same formulas with the minus sign (-) instead of plus (+).
In your Excel worksheets, the formulas may look similar to these:
To add 30 seconds to A2: =A2 + TIME(0,0,31)
To add 1200 seconds to A2: =A2 + (1200/86400)
To subtract 40 seconds from A2: =A2 - TIME(0,0,40)
To subtract 900 seconds from A2: =A2 - (900/86400)
How to sum time in Excel
The Excel sum time formula is the usual SUM function, and applying the proper time format to the result is what does the trick.
Supposing you have a few project times in column B and you want to add them up. You write a simple SUM formula like the one below and get the result in the default format such as hh:mm:ss.
=SUM(B2:B4)
In some cases the default time format works just fine, but sometimes you may want more, for example to display the total time as minutes and seconds, or seconds only. The good news is that no other calculations are required, all you have to do is apply custom time format to the cell with the SUM formula.
Right click the cell and select Format Cells in the context menu, or press Ctrl + 1 to open the Format Cells dialog box. Select Custom from the Category list and type one of the following time formats in the Type box:
- To display total time as minutes and seconds: [m]:ss
- To display total time as seconds: [ss]
The result will look as follows:
In order to add up more than 24 hours, you use the same SUM formula as discussed above, and apply one of the following time formats to the cell: To see how these custom time formats may look like in your Excel worksheet, please have a look at the screenshot below, where the same SUM formula is entered in cells A9 to A13: Note. The above custom time formats work for positive values only. If the result of your time calculations is a negative number, e.g. when you are subtracting a bigger time from a smaller time, the result will be displayed as #####. To display negative times differently, please see custom format for negative time values.
Also, please keep in mind that the time format applied to a cell changes only the display presentation without changing the cell's value. For example, in the screenshot above, cell A13 looks like text, but in fact it's a usual time value, which is stored as a decimal in the internal Excel system. Meaning, you are free to refer to that cell in other formulas and calculations. For more information, please see How to calculate and show over 24 hours, 60 minutes, 60 seconds.How to sum over 24 hours in Excel
Format
Displays as
Explanation
[h]:mm
30:10
Hours and minutes
[h]:mm:ss
30:10:20
Hours, minutes and seconds
[h] "hours", mm "minutes", ss "seconds"
30 hours, 10 minutes, 20 seconds
d h:mm:ss
1 06:10:20
Days, hours, minutes and seconds
d "day" h:mm:ss
1 day 06:10:20
d "day," h "hours," m "minutes and" s "seconds"
1 day, 6 hours, 10 minutes and 20 seconds
=SUM($B$2:$B$4)
Date & Time Formula Wizard - quick way to calculate times in Excel
Now that you know a bunch of different formulas to add and subtract times in Excel, let me show you the tool that can do it all. Okay, almost all :)
Here comes Ablebit's Date & Time Formula Wizard for Excel:
In the Date & Time Wizard dialog window, you switch to the Add or Subtract tab, depending on which operation you want to perform, and do the following:
- Click the Show time fields link in the left part of the window.
- Supply values or cell references for the formula arguments. As you fill in the argument boxes, the wizard builds the formula in the selected cell.
- When finished, click the Insert Formula
That's it! For example, this is how you can add the specified number of hours, minutes and seconds to the time in A4:
If you need to copy the formula to other cells, fix all references except the cell containing the original time (A4) with the $ sign like shown in the screenshot below (by default, the wizard always uses relative references). Then double-click the fill handle to copy the formula down the column and you are good to go!
Besides time calculations, the wizard can also add and subtract dates, get the difference between two dates, and calculate age from the birthdate.
If you are curious to try this tool in your own worksheets, you are welcome to download the evaluation version of our Ultimate Suite below.
This is how you calculate time in Excel worksheets. To learn other ways to manipulate dates and times in Excel, I encourage you to check out the resources at the end of this article. I thank you for reading and hope to see you on our blog next week!
Available downloads
Excel Time Calculations - formula examples (.xlsx file)
Ultimate Suite - trial version (.exe file)
1021 comments
I’m trying to do a rota so for example if I put some one down for say a 10:00 - 18:00 there entitled to 30 minute break so it calculates there hours for me minus the 30 minutes
Hi! Find the difference between the end time and the start time and subtract another 30 minutes. To set a specific time, use the TIME function. For example:
=A2-A1-TIME(0,30,0)
How do you convert a negative value from hh:mm to minutes? For example, if you were subtracting 9:00 PM and 7:30 PM and got -1:30, how would you convert that to -90.00?
Hi! Use IF function to calculate by the condition. Try the following formula:
=IF(A1-A2<0,A2-A1,A1-A2)*1440
I'm trying to find a formula that shows under time equation for puch in &out
Hi! Your task is not completely clear to me.To understand what you want to do, give an example of the source data and the expected result.
I have a column of end of work times. I want to know how to sum just the total number of minutes worked past 5 PM. Thanks!
Hi! Subtract the time 17:00 from each value as described in the article above. Use IF function to replace negative time differences with 0. Calculate the sum using SUMPRODUCT function. For example:
=SUMPRODUCT(IF(C2:C10-TIME(17,0,0)<0,0,C2:C10-TIME(17,0,0)))
IF that worked, I would be very happy. I can't spot the error, but I get an error message.
Hi! It is possible that you will get an error message if your time is written as text.
Please check what kind of data you are working with. Maybe this article will be helpful: Convert text to time in Excel.
What is the formula to calculate the working hours between the following (16/11/2023 09:08 and 23/02/2024 14:31) if working hours are Mon-Fri 07:30-16:00
Hi! Use the NETWORKDAYS.INTL function to calculate the number of working days between two dates. To calculate the working hours between dates, try this formula:
=(NETWORKDAYS.INTL(A1, B1,1 )-2)*TIME(8,30,0) + TIME(8,30,0)-MAX(0,(A1-INT(A1)) - TIME(7,30,0)) + TIME(8,30,0) - MAX(0,TIME(16,0,0)-(B1-INT(B1)))
Set a custom time format [h]:mm in the formula cell using these instructions: How to show over 24 hours, 60 minutes, 60 seconds in Excel.
Hi.
I used If function to find night time work hour for shift between 9PM to 6:AM for example clock in 2PM lock Out 10AM result 1 hours. but now i could not remember how to format the function. could you help please? thanks
Hi! Your example data does not match the desired result. Explain what you want to do.
I'm trying to find a formula that shows the difference between two times (seconds) in percentage.
For example, Current time is 18.2 seconds and New time is 16.8, how do i calculate the difference to show in percentage. Also what if the current time is 18.2 seconds and the New time is 55.9 seconds, is the formula different? Thanks in advance.
Hi! Since time in Excel is a number, I think this article will help you solve your problem: How to calculate percentage in Excel. For example:
=(A2-B2)/B2
Using a stopwatch with a "lap" function (made with VBA code), time is auto logged in column A as 0:00:00. When I use =SUM for the A cells, it does not auto add the times. (if A2 is 0:00:10, A3 is 0:00:07, A4 is 0:00:15, I put the SUM formula where I want the total to be, but it does not add A2 through A4 and only shows 0:00:00.)
Once the formula is in place, if I double click the A cells that have time in them and hit enter, then and only then will it add the data.
How do I get this to automatically add the data when times are added in the A column?
Hi! I cannot help you check how your custom function works, which I don't have. We do not help with the creation of custom functions, and we do not give advice on how to work with VBA.
I'm trying to add seconds to a starting time that's a negative value (say, A2='-0:20:00) but =A2+TIME(0,0,31) is not working even though I went and changed to 1904 date format in advanced options. Where should I go from here? I want negative time before a catalyst event at time=0:00:00. Then see values from 0:00:00, 0:00:30 all the way to 1:20:00 at 30 second intervals.
Hi! You cannot enter a negative time in a cell. But you can get a negative time in the 1904 date format using a formula like this:
=0-TIME(0,0,20)
or
=0-A2
where A2=0:0:20
Im trying to find a formula to add time.
Clock in at 10: out at 14: if they get to work before 11 ill pay minimum wage. After 11 they get pay servers rate.
What will be the formula to add hours before and sfter 11 separste
Hi! To find the number of hours before 11:00, find the difference between 11:00 and the start time. This is described in the article above. If this does not help, explain the problem in more detail. Provide me with an example of the source data and the expected result.
hi there. my question is let say
10434:34 which is 10434hours and 34minutes + 214:53 which is 214hours and 53minutes
how to create the formula. since i try but my answer is VALUE.
please guide me. thank you
Hi! Write these two values in two separate cells, for example, A1 and B1. Then find the sum =A1+B1. You can also find useful information in this article: How to show over 24 hours, 60 minutes, 60 seconds in Excel.
hi ,
=(C1+D1)-(A1+B1)
i am using this formula for calculating hours. but this formula only for less than 24 hours , how can i use this same formula for more than 24 hours
thank you
Hi! To show a time over 24 hours, you can use 2 ways.
First. Use a custom time format as recommended here: How to show over 24 hours, 60 minutes, 60 seconds in Excel.
Second. Convert the time to a number of hours. To do this, multiply by 24 as recommended here: How to convert time to decimal number, hours, minutes or seconds in Excel. I hope it’ll be helpful.
Howa to calculate the repetition of hours 8 and 12 bitween two dates ex: 15/02/2024 and 18/02/2024
Thank you.
Hi! If you have a range of date and time values, you can use the HOUR function to extract the number of hours in the range. You can then use the SUMPRODUCT function to count the number of hours that is equal to 8. For example:
=SUMPRODUCT(--(HOUR(A1:A15)=8))
I hope my advice will help you solve your task.
Hi, I am trying to figure out an average clock-in time on different days.
Say,
Day 1: 07:00
Day 2: 08:00
Day 3: 06:00
Day 4: 06:30
Day 5: 07:00
I would to know the formula that will tell me the average time the employee clocked in over the 5 days.
Thanks.
Hi! Calculate the average time using the AVERAGE function. You can find the examples and instructions here: Excel AVERAGE function to find arithmetic mean.
13:04:00 - 22:01:28
13:03:05 - 13:55:3013:57:16 - 21:29:5721:31:25 - 22:00:34
09:00:08 - 11:01:2911:01:31 - 18:02:00
i have 3 conditions i want to find out the total login hours for every condition with one formula
Hi! These conditions are text. Extract each time value from the text as described in these instructions: Excel substring functions to extract text from cell. Convert text to time as described here.
How to find the time difference is described in the article above. For example:
=TIMEVALUE(RIGHT(A1,8))-TIMEVALUE(LEFT(A1,8))
Hi, I am creating a schedule tracker for teammates in excel. When I write the shifts per employee, I utilize one box per day per teammate. So under Teammate "Zach" in box 1 it will say 4:00-13:00, box 2- 4:00-12:00, and box 3- 4:30-16:30. Is there a way to sum the total number of hours for all those days in each box?
Hi! Your time intervals are written as text. Split text to text strings and convert the text strings to time and find the difference.
=TIMEVALUE(MID(A1,SEARCH("-",A1)+1,10)) - TIMEVALUE(LEFT(A1,SEARCH("-",A1)-1))
Read more: Convert text to time using TIMEVALUE function.
I am trying to create a timesheet that automatically calculates the amount of time between 4 times, adding the hours worked and subtracting the lunch time. From there I need 8 hours or less to populate under "regular hours" column, and any overage to calculate under OT hours. I tried to do a sumif and tell it to calculate the hours and minutes, which it did, but it won't accept me telling it to put 8 if it sums to more than 8 hours.Day In
IN out for lunch OUT Reg OT
Monday 6:30:00 AM 11:00:00 AM 11:30:00 AM 5:00:00 PM 8.00 2.00
Tuesday 6:30:00 AM 11:00:00 AM 11:30:00 AM 5:00:00 PM 8.00 2.00
Wednesday 6:30:00 AM 11:00:00 AM 11:30:00 AM 5:00:00 PM 8.00 2.00
Thursday 6:30:00 AM 11:00:00 AM 11:30:00 AM 5:30:00 PM 8.00 2.50
Friday 6:30:00 AM 11:00:00 AM 11:30:00 AM 6:00:00 PM 8.00 3.00
Saturday 6:30:00 AM 11:00:00 AM 11:30:00 AM 4:45:00 PM 9.75
Hi! I can't guess how you could use the SUMIF function to calculate the time intervals. Try this formula and describe the condition using the IF function.
=IF(((C2-B2)+(E2-D2))>TIME(8,0,0),8,((C2-B2)+(E2-D2))*24)
You can also find useful information in this article: How to convert time to decimal number in Excel.
Can you please make me formula to reflect below answers YES and NO as per these times
carryover
8/30/2023 21:59 8/31/2023 8:00 yes
8/30/2023 21:59 8/31/2023 0:00 yes
8/30/2023 21:59 8/30/2023 23:59 no
8/30/2023 22:00 8/30/2023 23:59 no
8/30/2023 22:00 8/31/2023 23:59 no
Hi! I don't want to guess by what logic you set Yes or No. Also, it is unknown if the date and time are written in the same cell or if they are 2 separate values.
Hello
I am needing help try to make a formula to help me with employees time.
For instance they start at 5:00 AM normally but if they are late (After 5:02 their time doesn't start until 5:15). Also if they clock out before the next quarter hour say 2:40 PM it is rounded down to 2:30 and minus lunch time of 30 minutes daily. I am trying to do this without having to write out the date in the formula as I'm just double checking their math on each individual day i.e. start time A1 end time A2 lunch A3.
Hi! Extract the hours and minutes using the HOUR and MINUTE functions. If you want to round the time to the nearest 15 minutes forward, use the CEILING function. To round to the nearest 15 minutes backward, use FLOOR. Then get the time value using the TIME function.
=TIME(HOUR(A1),CEILING(MINUTE(A1),15),0)
=TIME(HOUR(A1),FLOOR(MINUTE(A1),15),0)
For more information, please visit: How to round to nearest 5 / 10 / 100 / 1000.
Hi.
I'm working on my work sheet with all kinds of shifts. My shifts can start at any time of day and also end in any time. Of the sime day or next day.
B4=start date
D4=start time
E4=end date
F4=end time
I can calculate length of shift, break, day hours but I can't calculate night hours which are only between 22:00 to 6:00 next day.
As example, cases can be:
1. Shift starts 1.1.2024 at 18:00 (6:00PM) and ends 2.1.2024 at 2:00 (2:00AM);
2. Shift starts 1.1.2024 at 0:00 (12:00AM) and ends 1.1.2024 at 8:00 (8:00AM);
3. Shift starts 1.1.2024 at 23:00 (11:00PM) and ends 2.1.2024 at 7:00 (7:00AM);
4. Shift starts 1.1.2024 at 6:00 (6:00AM) and ends 1.1.2024 at 14:00 (2:00PM);
5. Shift starts 1.1.2024 at 16:00 (4:00PM) and ends 2.1.2024 at 0:00 (12:00AM);
6. Shift starts 1.1.2023 at 15:00 (3:00PM) and ends 1.1.2024 at 23:00 (11:00PM);
7. Shift starts 2.1.2024 at 0:00 (12:00AM) and ends 2.1.2024 at 7:00 (AM);
8. Shift starts 1.1.2024 at 23:00 (11:00PM) and ends 2.1.2024 at 4:00 (AM).
Can somebody help me with formula to count only night hours?
Hi! To calculate night hours at 10:00PM and ends 6:00AM, try this SUMPRODUCT formula:
=SUMPRODUCT((ROW($1:$360)>MOD($D4,1)*1441) * ((ROW($1:$360)<(MOD($F4,1)*1441+(TRUNC($F4)>TRUNC($D4))*1440)))) / 1440+SUMPRODUCT((ROW($1321:$1800)>MOD($D4,1)*1441) * ((ROW($1321:$1800)<(MOD($F4,1)*1441 + (TRUNC($F4)>TRUNC($D4))*1440))))/1440 + SUMPRODUCT((ROW($2761:$3000)>MOD($D4,1)*1441) * ((ROW($2761:$3000)<(MOD($F4,1)*1441+(TRUNC($F4)>TRUNC($D4))*1440))))/1440