How to calculate time in Excel - time difference, adding / subtracting times

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:

=End time - Start time

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: Calculating time difference in Excel

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: The elapsed time is displayed differently depending on the applied time format.

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")

Calculating time difference with TEXT function

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:

=(End time - Start time) * 24

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) Calculating hours between two times in Excel

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).

=(End time - Start time) * 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 Calculating total minutes between two times in Excel

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).

=(End time - Start time) * 86400

In our example, the formula is as follows:

=(B2-A2)* 86400 Calculating total seconds between two times

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. Calculate time difference in one unit ignoring others

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 Calculating elapsed time from a start time to now

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: Calculating elapsed time over 24 hours

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 Calculating elapsed time without dates

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" A user-friendly Excel time difference formula

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 :) Excel time difference formula that ignores zero values

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" Subtract the start time from the end time and apply the custom time format to the cell.

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. Changing to the 1904 data system

Click OK to save the new settings, and from now on negative times will be displayed correctly, like negative numbers: In the 1904 date system, negative times are displayed 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". A formula to calculate negative times in Excel

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

=Start time + TIME(N hours, 0, 0)

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) TIME function to add under 24 hours

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:

= Start time + (N hours / 24)

For example, to add 28 hours to the start time in cell A2, enter the following formula:

=A2 + (28/24) Universal formula to add hours to a given time in Excel

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:

=Start time + TIME(0, N minutes, 0)

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:

=Start time + (N minutes / 1440)

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) Adding and subtracting minutes in Excel

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:

=Start time + TIME(0, 0, N seconds)

To add more than 59 seconds, use the following formula:

=Start time + (N seconds / 86400)

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) A SUM formula to add up times in Excel

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: Apply the custom time format to display total time as minutes and seconds, or seconds only.

How to sum over 24 hours in Excel

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:

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

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:

=SUM($B$2:$B$4) Adding up more than 24 hours in Excel

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.

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: 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: Add hours, minutes and seconds to the original time in Excel

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! Formula to add hours, minutes and seconds to time in Excel

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)

977 comments

  1. Hello,

    I have a situation where I calculate the answering time, but I do not want to calculate the time outside of working hours.
    For example:

    Time of receiving e-mail: 02.02.2023. 15:50
    Time of receiving answer: 03.02.2023. 08:30
    I want the result to be: 40 minutes.

    How to do it?
    Thank you.

  2. working schedule /day- 8.00 am to 5.00 pm wherein 1.00 pm to 2.00 pm lunch back
    one project start work 26/1/2023 at 11.00 am.
    weekly holiday=27/1/2023
    weekly holiday=28/1/2023
    time required to complete project =43 hr.
    Finished date & time of the project=??
    need formula plz??

      • hi,
        thanks
        Finished date & time =2/2/2023 at 11.00 am
        but manually calculation actual finished date & time should =2/2/2023 at 3.00 pm.

        start time=26/1/2023 at 11.00 am (wherein work schedule =8.00 am to 5.00 pm),

        need help for solution please.

  3. Status Date Time Hours
    Exit 27-Jan-23 4:58:14 AM
    Entry 27-Jan-23 3:25:33 PM
    Entry 27-Jan-23 3:25:49 PM

    how i can get hours above

  4. HI,
    I'm trying to get total hours worked but its coming up 12:00:00 AM
    I'm using the AutoSum option
    Thanks

  5. Hi, Found your tutorials very useful. Kindly help with the below task.

    I'm trying to prepare a weekday-wise task schedule, for item dispatching purposes.
    I require to view the time with WEEKDAY (ie: WED 15:30).
    Ex: If the dispatch day/time of delivery of one item, is WED 15:30, our preparation starts 36 hours prior, so at " Preparation Time" column should be displayed as " TUE 03:30", where I can analyze the hourly workload on each Day of Week.

    Thanks.

    • Hello!
      To extract the time from a date, extract the fractional part of the number using the INT function.
      For example,

      =IF((A1-INT(A1))>TIME(15,30,0),A1-36/24,A1)

      I hope it’ll be helpful.

  6. Im trying to count timestamps i made with a macro essential enters now() if another cell is filled but i want to count the time stamps that fall into a range of 9am-12am 1pm-3pm and 3pm-5pm any idea how to format timestamps so i can use count ifs to determine if they are within those ranges?

  7. Anyone have an idea how I can compute for cycle time? But only taking into account a specific timeframe.

    Example:
    Timeframe is 9:00AM to 5:00PM
    But the device was assembled with times:
    8:00AM-12:00NN
    3:00AM-7:00AM
    2:00PM-7:00PM

    Is there a formula where I can compute for the cycle time but only for 9:00AM-5:00PM time?

  8. Hi, I need your help.

    How to get the Duration time if this is the format?
    DATE TIME DURATION LOGIN TIME LOGOUT TIME
    30-Aug 01:00 PM - 10:00 PM 9:00:00 8/30/2017 13:00 8/30/2017 22:00

    I really need an answer for this. Thank you so much ♥

    • DATE-----------T------IME-------------------------- DURATION---------------- LOGIN TIME ----------------------LOGOUT TIME
      30-Aug------01:00 PM - 10:00 PM------- --------9:00:00 --------------------8/30/2017 13:00--------------- 8/30/2017 22:00

      This one. I need the formula for this. Thanks!

    • Hi!
      Have you tried the ways described in this blog post? If they don’t work for you, then please describe your task in detail, I’ll try to suggest a solution.

  9. Hi Guys...how do you convert two times into hours and minutes..

    Example

    6:00 am --start time
    8:30 --- end time

    Answer is 2.50 where the 50 is the 30 minutes divided by 60 (30/60)

    Need the formulae to work on various time differences like this

  10. I know the start time 7:41 AM, I know the time out for lunch, 11:38 AM, I know when the time clocked back in after lunch 12:16 PM.
    The person has to work 8 hours. I need to calculate the ending time based off the three known times and the total duration of 8 hours.
    What is the formula for calculating the ending time?

    • =TIME(8,0,0)-((Lunch Start - Start Time) + (Lunch End - Lunch Start))

  11. I am trying to create a excel formula which will return a result of decimal hours, calcluated from start time, end time and reported down time, currently I am using cell format h:mm AM/PM for start and stop time, and then I manually subtract the minutes reported for down time and convert sum to decimal hours. for example -->

    Raw Data:
    Start time 5:00 AM
    End Time 1:32 PM,
    Minus 87 minutes down time (which also varies daily)
    Manually calculated its 6.08 in decimal hours

    I am looking for a formula and cell format suggestions to have excel do the calculations after start, end and break data have been added to cells.

  12. Hi, Is there a formula to get the time range and date or just even the time range? Example 7/1/2022 0:49:00. This will fall into the 12am to 1am range under Friday? I am trying to get how many entries came on a certain day for a certain time range. Friday 12am-1am we received 10 tickets.
    Monday Tuesday
    6 AM - 7 AM

  13. Hello,
    I am trying to calculate regular hours and OT hours based on the clock.
    8am - 4pm is regular time
    All other times are OT.
    person would input this start time to end time, in A1,B1 (6:00,1300)
    from 6-8 would return OT hours (2), shown in cell C1
    from 8-1300 would return regular hours (5), shown in cell D1

    • Hello!
      Calculate regular time with the formula:

      =B1-A1-IF(A1>A2,0,IF(A1>A2,0,MAX(A2-A1,A1-A2)))-IF(B1A2,0,MAX(A2-A1,A1-A2))
      =IF(B1

      • Hello Alexander,

        I would like to ask which value A2 cell is referring to in your formula.

        I need to calculate regular time (8am-5pm) between to dates.

        • Calculate regular time with the formula:

          =B1-A1-IF(A1>A2,0,IF(A1>A2,0,MAX(A2-A1,A1-A2)))-IF(B1<B2,0,MAX(B2-B1,B1-B2))

          =IF(A1>A2,0,MAX(A2-A1,A1-A2))

          where A2 is 08:00. B2 is 16:00.

          • I am unclear about your formula(s) above.
            I put the following in:
            A1 is 06:00
            B1 is 11:00
            A2 is 08:00
            B2 is 16:00
            C1 is =B1-A1-IF(A1>A2,0,IF(A1>A2,0,MAX(A2-A1,A1-A2)))-IF(B1A2,0,MAX(A2-A1,A1-A2))

            • It appeared to cut off my last couple of lines. With the formula above for C1, it returned 0.125. I was expecting 3. What is =IF(A1>A2,0,MAX(A2-A1,A1-A2)) used for and where?

  14. Hi All,

    I have a range of times and im trying to get the start and end time for productivity so i can work out hours used

    I have a lot of staff so just trying to save time for myself

    I have a VLOOKUP for the start time which is fine
    But I'm using for the end time =MAXIFS(N:N,J:J,"="&O2) because I'm trying to find the biggest time in the range but is just returning back 00:00:00

    Any help would be much appreciated

    • Hi!
      Unfortunately, without seeing your data it is difficult to give you any advice. Please provide me with an example of the source data and the expected result.

  15. Hi - I found your blog very helpful. However, I am stuck when trying to find the difference between two date/time stamps while excluding hours outside of 8:00AM to 5:00PM. I know how to calculate NETWORK days and I know how to calculate hours between date/time. I just don't know how to exclude non-working hours.

    For example, Cell AA3 is (Autogenerated from database) 10/25/2022 2:21PM and Cell AC3 is 10/26/2022 8:44AM the difference should be 3 hours and 23 minutes (Excluding non working hours). How do I find the difference in NETWORKDAYS and hours together? Or do network days and hours need to be split up into two separate columns? I will need to average out the columns once I figure out the date/time differences between cells.

    Thank you and appreciate the help!

    • Here is where I am at so far...should work...but it doesn't for some reason.

      =(NETWORKDAYS(A2,C2) -1)*(upper-lower)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),upper,lower),upper)-MEDIAN(NETWORKDAYS(A2,A2)*MOD(A2,1),upper,lower)

  16. Hi! Can somebody help me with a formula? I need to compute the rectification time duration between two separate opening hours in a day. The first Opening Hour is from 6:00am to 10:00am, the second is from 7:00pm to 11:00pm. The time in between 10am and 7pm is not counted because it's not within the Opening hours.

    1st scenario: If the rectification time is from 7:00am to 8:00am, then the duration is 1 hour.

    2nd scenario: If the rectification time is from 7:00am to 3:00pm, then the duration is only 3 hours (10:00am to 3:00pm is not counted because it's not within the opening hours)

    3rd scenario: If the rectification time is from 7:00am to 8:00pm, then the duration is 4 hours because the rectification time crossed over the second opening hour (from 7pm to 8pm)

    Hope somebody here can help me. Thanks a lot!

    • Hello!
      The start rectification time and end time are written in A2 and A3.
      Opening hours are written in A1:D1.
      Try this formula:

      =IF(B1>A2,B1-A2,0)- IF(A1>A2,A1-A2,0) +IF(A3>C1,A3-C1,0) -IF(A3>D1,A3-D1,0)

      • Hi Alexander! Thanks a lot for your reply but I always get the answer "4" every time.

        • This is my formula but is only applicable for Scenario 1 above,
          where A2 is start time and A3 end time and B1 is end of 1st opening hour or 10:00am

          =IF(A3>=B1,A3-A2,0)

          When I apply the above formula for scenario 2 and 3, it will include the number of hours not within the Opening Hours.

          I just couldn't get around my head on this.

          Thanks!

        • Hello!
          If I got you right, the formula below will help you with your task:

          =(A2<=B1)*((A3-A2)-IF(A1>A2,A1-A2,0)-IF(A3>B1,A3-B1,0)) + ((A3-A2)-IF(C1>A2,C1-A2,0)-IF(A3>D1,A3-D1,0))*(A3>=C1)

          • Hi! Thank you, Alexander. Will try this out.

  17. Hi I have the date and time data where as i need to calculate the hours in logic way
    for example : ( 01-12-2022 19:42:00 - 02-12-2022 11:55:00 = -16:13 Hours ) but if i have recd the data on 01-12-2022 post 6:30 PM the time should calculate from next day 9:30 am, so ideally the total time consume from ( 02-12-2022 09:30:00 to 02-12-2022 11:55:00 ) = 2:25 .

    Pls provide formula

    • Alexander sir pls support

      • Hi!
        If I understand your task correctly, try the following formula:

        =B1 - IF(A1-INT(A1)>TIME(18,30,0), A1+TIME(15,0,0)-(A1-INT(A1)-TIME(18,30,0)), A1)

        • No Sir it doesn't work,
          My task is to understand you { Rec Time - 01-12-2022 13:26:00 } - { Send time - 02-12-2022 19:58:00 } = 30:32 Hour whereas here it is calculating the entire hours
          But if i remove the non working hours i;e from > 18:30 then and next day working hours i;e < 09:30 AM. and the send time is { Send time - 02-12-2022 19:58:00 } so ideally total time taken for work is = 10:28 hours
          one more example :
          Recd Time : 01-12-2022 19:42:00 - Send Time : 02-12-2022 11:55:00 = 16:13 Hours Logically
          But
          Recd Time : 01-12-2022 19:42:00 - Send Time : 02-12-2022 11:55:00 = 2:25 Mins ( Ideally it should calculate only working Hours ) i have manually removed working hours and calculated here i need this in formula

          Sorry for long texture.

          • Hi!
            The formula I sent to you was created based on the description you provided in your first request. However, as far as I can see from your second comment, your task is now different from the original one.

            =B1 - IF(A1-INT(A1)>TIME(18,30,0), A1+TIME(15,0,0)-(A1-INT(A1)-TIME(18,30,0)), A1+TIME(15,0,0))

      • Can any one support me in this formula

  18. if work start on 5-3-15 10:30 PM proposed work completed after 76478hr 45 minutes and daily working hrs are 6hrs how to calculate work completed time and date

    • Hello!
      To calculate working time in days, use the recommendations from the article above:

      =INT(A2/6)+MOD(A2,6)/24+A3/1440

      A2=76478
      A3=45
      Then add to the start time.

  19. Hi
    In my workplace I constantly need to add 50% to the allotted written time for exams.
    For example exam time is:
    08.00-12.00 and for the students I take care of they get 50% extra time which here would be 08.00-14.00

    Is there a formula that can take the original time add 50% and show the result in clock time. If i write 08.00-12.00 I want the next column to show the written times with the added 50%. It would save me a lot of time to not have to count in my head and manually write the time..
    Thanx =)

  20. Hi,

    Is there a way I can combine the formula of concatenate date in one cell and get the difference between the two dates?
    Sample:
    Cell A1 10/24/2022
    Cell B1 13:35
    Cell C1 10/25/2022
    Cell D1 02:05
    Cell E1 =CONCATENATE(TEXT($A1,"mm/dd/yyy")&" "&TEXT($B1,"hh:mm:ss"))
    Cell F1 =CONCATENATE(TEXT($C1,"mm/dd/yyy")&" "&TEXT($D1,"hh:mm:ss"))
    Cell G1 Result

    Thank you in advance

  21. Morning

    I have used the Formula TEXT and found the time difference between two times across 4 rows, =TEXT(G1-F1,"h:mm:ss") (n.b. F:F and G:G data includes dd:mmm:yyyy if this has any bearing), which works successfully. In the Time Difference column I've copied the TEXT formula down the relevant rows to determine each time difference. At the bottom of the Time Difference column, =SUM(H1:H4) returns 00:00:00. Is there any reason this does not function as expected?

    Cheers

    Dan

  22. I have used the Formula TEXT and found between 2 different times the hours and minutes. I have done this for a whole month. but now i want the total hours worked on that month. Which function should i use?

  23. Hello Alexander! I am looking for a formula to calculate the years, days, and months along with a subtotal of the length of service. I could not get the subtotal to match the total of each hire date and ending day of this employee. I figured I will need to add the day in with the years and months. I still wasn't getting an accurate subtotal. What am I doing wrong? And how would I do the formula? Thanks!

    ID Last Name First Name Date Hired End Date Length of service
    1234 DOE DARREN 11/19/1998 10/18/1999 0 years,10 months
    1234 DOE DARREN 04/05/2001 02/05/2004 2 years,10 months
    1234 DOE DARREN 07/18/2004 01/12/2005 0 years,5 months
    1234 DOE DARREN 02/18/2009 08/29/2011 2 years,6 months
    1234 DOE DARREN 01/21/2013 08/10/2019 6 years,6 months
    1234 DOE DARREN 04/21/2021 05/09/2021 0 years,0 months
    1234 DOE DARREN 02/07/2022 10/04/2022 0 years,7 months

    SUBTOTAL

    • Hello!
      I don't really understand what subtotal you want to calculate. However, I assume that the "Length of service" column contains text, not numbers. You can't execute any mathematical operations on the text.
      To calculate length of service, you can use this guide: Calculate number of days between two dates in Excel.
      Please provide me with an example of the expected result, and I will try to help.

  24. Hi Sir.Good Day.Please help me with the right formula of late,undertime and Overtime.Im always getting the wrong formula.
    Start Time=07:00
    End Time=16:00

    For late.6min-35min=0.5 36min-1.06hr=1
    For undertime.6min-35min=0.5 36min-1.06hr=1
    For Overtime.(17:00-17:29=1),(17:30-17:59=1.5),(18:00-18:29=2)

    A B C D E
    1 IN OUT LATE UNDERTIME OVERTIME
    2 07:06 15:55 0.5 0.5
    3 07:00 18:20 2

    Thank You,

    • Hello!
      To find the desired time interval, use the MATCH function with Match_type=1
      In columns A and B, write down the values
      07:00 0
      07:06 0.5
      07:36 1
      08:06 1
      08:07 0
      14:54 1
      15:25 0.5
      15:55 0
      17:00 1
      17:30 1.5
      18:00 2
      18:30 0
      Formulas for calculating of late, undertime and overtime:

      =INDEX(B1:B5,MATCH(D1,A1:A5,1)) late
      =INDEX(B6:B8,MATCH(E1,A6:A8,1)). undertime
      =IFERROR(INDEX(B9:B12,MATCH(E1,A9:A12,1)),0) overtime
      Hope this is what you need.

  25. If i want to do an if statement based on the # of hours, what am i missing.

    eg. 4hrs=$50, 4-8hrs=$100, >8hrs=$150
    cell a1=1:00am, b1=6:00am, c1=b1-a1, d1=IF(C1<4,50,IF(AND(C14),100,150))

    I've tried the above but c1 does not give me 5 as the answer unless i turn it to "hour" format, and d1 gives me answer of 150.
    Final answer should be 100 as it falls within 4-8hrs.

  26. Hi! I'm having trouble creating the formula for counting working time with consideration of working hours.

    Working hours: 8:00 - 17:00

    Example:
    A1 = 8/18/2022 16:50 ; B1 = 8/19/2022 8:20 ; C1 should return 30 minutes.
    A2 = 8/18/2022 9:30 ; B2 = 8/18/2022 12:00 ; C2 should return 2 hours and 30 minutes.
    A3 = 8/18/2022 17:30 ; B3 = 8/19/2022 7:54 ; C3 should return 0 hours and 0 minutes.

    Hoping to get some help here. Thanks!

  27. Hi, Good day! I've been reading all the comments here but I cannot find any related of my problem here. I want to sum my time in one go and it goes like this:

    7:03-11:19 and 1:00-7:00

    I came up with a formula like this:
    =Round(Sumproduct(11:19-7:03)+(7:00-1:00)*24,2

    But as expected, it doesn't result to 10.27 hrs

    What formula should I use for it? Thank you in advance.

  28. Dear mister Alexander Trifuntov,
    I am sorry I make a mistake. I think this day my body was in bed in my head on the moon.
    All work perfectly.

    Do not know for what I want 11:30 – 3:00 = 3:30 since the real answer finally is 15:30 like in your formula.
    Sorry for this mistake and thanks a lot and have a nice day!

  29. Thanks for your feedback. Really appreciate.

    All 24H format (Format Cell > Time > 13:30)
    Example #1
    O8: 3:00
    P7: 11:30

    Normally must show 3:30
    Trying what you say:
    =IF(O8>P7,P7-O8+1,P7-O8)
    Give 15:30, which is not ok because show result on 24 formats.

    Example #2
    O11: 4:00
    P10: 14:30

    Normally must show 10:00
    Trying:
    =O11+1-P10
    Give 10:00, which is ok

    Thanks by advance!

    • Hi!
      The result of your example 1 I can't understand and repeat. Excel stores time in 24-hour format. Please read the above article carefully. 11:30 is 11:30, not 23:30. Write the time correctly.

  30. Hi,

    In the following, I want: End – Begin.
    Format of time is 24 hours (0:00 = 24:00)

    For example:
    Begin 11:30
    End: 3:00

    End - Begin = 3:00–11:30 = 15:30

    Begin End
    11:30 3:00
    11:30 4:00
    14:00 4:00
    13:30 5:00
    10:30 4:30
    14:00 5:30
    12:30 5:00
    15:00 6:00
    14:00 5:00
    16:00 7:00
    14:00 7:00
    14:00 9:00
    17:30 9:00
    17:30 9:00
    14:30 9:00
    16:00 10:00
    13:30 0:00
    13:30 0:00
    5:30 17:00
    2:30 22:00
    3:30 22:00
    5:00 22:30
    4:50 20:45
    6:40 21:40
    6:15 22:30
    6:20 0:30
    6:05 0:30
    6:25 0:00

    Thanks by advance.

  31. Hello,
    I have read your post and the comments but I can't find what I need. I am trying to figure out the hours between days in military time. If possible I am trying to gee the dates in separate cells. i.e. Start date, start time, end date, end time. Product would be total hours. (3/19/2012, 0645, 3/20/2012, 1400, total is 31.25 hours)
    Please help,
    Thank you,
    Carlos

    • Hello!
      Use the TIME function to convert text to time. Find the date and time difference and multiply by 24 to get the hours.

      =(C1+TIME(LEFT(D1,2),RIGHT(D1,2),0)-A1-TIME(LEFT(B1,2),RIGHT(B1,2),0))*24

      I hope it’ll be helpful.

  32. Hi there,

    I am trying to calculate time between two points in a video. For example, finding the difference between 02.54.42 (2 minutes, 54 seconds, 42 milliseconds) and 01.29.99 (1 minute, 29 seconds, and 99 milliseconds). I have tried formatting the cells to mm.ss.00 and subtracting using =A1-B1 (A1 having the larger number) but I get an error #VALUE. I want the answer to come out in the same format. Do you have any tips for making this calculation work in excel?

    • Hi!
      To calculate the time difference in milliseconds, write the minutes and seconds in separate cells. For example, A1=2, A2=54.42
      Use formula

      =(A1/1440+A2/86400)-(B1/1440+B2/86400)

      and set custom time format hh:mm:ss.000
      I hope it’ll be helpful.

  33. How to use formulas to the full column.

  34. I wanted to calculate 5 digit hours with minutes, but I am unable to do so. For eg : 12345:55 + 54231:02 = 66576:57, But I dont know how to do this in excel, Please can someone help me with the same?

  35. Good afternoon Sir,

    How to get end date and time if i have start day and time together and to add "n" working hours excluding non working hours.

    example 1) if start date=02/06/2022 02:00 and to add 4:00 working hours and the working hours are from 08:00 to 18:00 and the non working hours to be excluded are of from 18:00 to 08:00 and the end date should be like 02/06/2022 12:00. what is the formula for this one sir.
    2) if start date=02/06/2022 16:00 and to add 4:00 working hours and the working hours are from 08:00 to 18:00 the and the non working hours to be excluded are of from 18:00 to 08:00 and the end date should be like 03/06/2022 10:00. what is the formula for this one sir.

    please reply

  36. Hello there,

    I am struggling with the following scenario. I work for an airline. I am trying to calculate delays. For example, a flight was scheduled to arrive at 23:32. The actual arrival time is 00:15. How would I calculate the results to show the amount of time the flight was delayed when it crosses over into the next day? I tried something like this, but I am not getting the results I wanted: =IF(E21-D21>0,E21-D21,"-"&TEXT(ABS(E21-D21),"h:mm")) The result comes back as -23:17. Thank you for your help!

    • Hi!
      This question has already been discussed many times on our blog. If the start time is greater than the end time, then use the formula:

      =IF(A1>B1,B1+1-A1,B1-A1)

      Don't forget to set the time format in the cell.

  37. i have two columns in Excel 2016. the first beginning with 5/1/2022 11:44, the second column 2d 23h 47min, I need to have a formula that can add these two columns and come up with a third column with new m/d/yyyy h:mm.

    • Hello!
      You can extract three numbers from the text into separate cells with the help of these formulas:

      =--CONCAT(IF(ISNUMBER(--MID(MID(A2,1,SEARCH(" ",A2)-1),ROW($1:$94),1)),MID(MID(A2,1,SEARCH(" ",A2)-1),ROW($1:$94),1),""))
      =--CONCAT(IF(ISNUMBER(--MID(MID(A2,SEARCH(" ",A2)+1, SEARCH(" ",A2,SEARCH(" ",A2)+1)-SEARCH(" ",A2)-1),ROW($1:$94),1)), MID(MID(A2,SEARCH(" ",A2)+1,SEARCH(" ",A2,SEARCH(" ",A2)+1)-SEARCH(" ",A2)-1),ROW($1:$94),1),""))
      =--CONCAT(IF(ISNUMBER(--MID(MID(A2,SEARCH(" ",A2, SEARCH(" ",A2)+1),20),ROW($1:$94),1)), MID(MID(A2,SEARCH(" ",A2,SEARCH(" ",A2)+1),20),ROW($1:$94),1),""))

      To convert these numbers to time, use these guidelines: How to convert numbers to time format in Excel.

  38. I have two dates = 02/22/2022 11:00 AM & 03/22/2022 08:26 AM and I am using formule INT(date1 -date2.
    format of both excels is the same still I recieve #value error. Please help.

  39. I am trying to do a countif based on times. For example, I have an activity that occurs at any point within 24 hours. I am trying to count how many times the activity occurs between 07:00 and 19:00 (18:59, actually). I have dates associated with the times as well which I don't need for this calculation. For example, in a data set that includes the two cells with the following information:
    1/15/21 4:13
    2/13/21 15:50
    I would like to include the second cell (time of 15:50) into my countif but not the first cell (time of 4:13).

    How could this be addressed?

  40. How to Calculate Hours between two Times in ONE CELL.
    For Example.
    My input in A1 is [10-10]. Its Hours to Hours. If I'm working 10:00 AM to 10:00 PM its total 12 hours.
    So how can I get TOTAL Hours if I give input [hours AM - hours PM] in a single CELL

  41. hi,
    would be grateful if you help me on below issue.

    i have 2 dates (start date & End Date) and need return values in hours in two category divided. category 1, Peak hours (10PM - 5AM) and Category 2 is Non- Peak Hour (5AM- 10PM).

  42. Hello Alex, thankyou for your post, can you help me with my problems? I really hope you can assist me

    I want to know how to subtract the video time duration from the video remaining time duration

    for example, I want to convert 01:10/01:38:30 (video duration time) to the 01:37:20/01:38:30 (video remaining time)\

    all I want to do is just substracting 01:38:30 to 01:10 but the excel format keeps converting my time duration to AM and PM format

    I really hope you can answer me, thank you Alex

  43. Hello, can you help me with my problem?
    I have database where is a lot of cells with contains time in the format for example 1h 30m
    Is it possible to automatically convert that format to something like that: 1:30 ?
    I will be very thankful for your help

  44. can you help to calculate time between 2 dates but you remove non working hours of 18H00 to 07h00

    Thank you

  45. I have data where the initial clock was set wrong e.g., 1/9/1930 11:00 but should have been 9/14/2021 1:15. I can get the date corrected using =DATE(YEAR(B3)+91, MONTH(B3)+8,DAY(B3)+5) and time corrected using =B3+TIME(2,15,0). Is there a way to correct them both using one formula and keeping the original format? When I tried =B3+(47829600/1440) it returns only the date and no time. Thanks

  46. Hi! Thank you so much for this instruction! I didint found one more thing i was looking for.
    So,
    Im working between 7.00am - 3:30pm monday - friday. I have these "saldo hours". You can collect 1 saldo hour before 7.00am and 3 saldo hours after 3.30pm.

    Example

    Working between 6:45am - 3:35pm. Get paid normal 8h (30min not paid lunch break) and collect 20minutes of saldo.

    Now my saldo is +0:20h

    Next day working 6:00am - 3:15pm Get paid normal 8h (30min not paid lunch break) and collect 45minutes of saldo. (coming 60min before and leaving 15min early - total 45min)

    Now my saldo is +1:05h

    So how to create this kind of function or formula, which can trakt the saldo hours?

    Thank you so much!!

    • Hi!
      Determine the time using the TIME function. Use the IFERROR function to avoid errors in the calculation result.

      =IFERROR(TIME(7,0,0)-A1,0)+IFERROR(B1-TIME(15,30,0),0)

      I hope my advice will help you solve your task.

      • Hi!

        Thank you for fast answer!

        That is not working.

        I use one column for time i go to work, next column for time i leave. Third column calculate the total time with this formula =(C3-B3)-TIME(0;30;0).

        But how i can create the forumula calculate from that time what is normal work hours (8h) and after that rest goes to saldo.

        Thank you!

        • Hi!
          The formula I sent to you was created based on the description you provided in your first request.
          The formula calculates the saldo you wanted to calculate. Explain what exactly doesn't work.

          • Hi!

            Now its working, i had some typo with , and ;.

            Thank you so much!

            I have one another problem, what i cant solve, in another thing.

            So i use this device to measure things and i use excel to collect data. Somehow this device sending data in "wrong" format. So if the decive show negative value excel turn it positive with + and if value is positive excel shows also positive value without +. And i need to keep number format in "text" otherwise there is problem with formula.

            Example:

            Device value is -0,12 -> excel shows +0,12
            Device value is 0,13 -> excel shows 0,13

            Is there anything i can do in excel? From device side there is nothing i can do.

            • One more thing.. sorry to replay so many times..

              What if the saldo is negative? that formula is not working for that. Sometimes i do short day and use saldos.

              example

              working between 06:00 - 14:00, so saldo go negative 0:30h.

              thank you!

              • Hi!
                The formula I sent to you was created based on the description you provided in your first request.
                If you had specified all the terms at once, we would have saved a lot of time.

                =IF((((TIME(7,0,0)/24-A1/24)+(B1/24-TIME(15,30,0)/24))*24)<0, "-"&TEXT(-((TIME(7,0,0)/24-A1/24)+(B1/24-TIME(15,30,0)/24))*24,"h:mm"), ((TIME(7,0,0)/24-A1/24)+(B1/24-TIME(15,30,0)/24))*24 )

                Use time format in this cell.
                Negative time is written as text.

              • Hi!

                Now everything is working right! Thank you very much!

  47. Hello,

    Thanks for the tips. Unless I missed it in the article, I'm not seeing the solution I'm looking for. I'm planning courier routes and would like to display the transfer time for each stop. For the first column, I have the arrival time (e.g., 8:00AM). For the second, column, I have the transfer time listed (e.g., 8:00AM - 8:15AM). Is there a function I can use to display the transfer with the only variable being transfer time (e.g., 15 minutes, 30 minutes, etc.?) or would this require additional columns?

    Thanks!

    • Hello!
      If I understand you correctly, you want to add time to the arrival time (15 minutes)
      Please try the following formula:

      =A1+TIME(0,15,0)

      If this is not what you wanted, please describe the problem in more detail.

      • Hello,

        This is close, but I'm also hoping there is a way to display both the original time and the time plus variable in the same cell so that if the first column reads 8:00AM, the second column would read 8:00AM - 8:15AM.

        Thanks so much

  48. how to sum numbers and time in one column , for example ( 4151485 1:00 PM 10:00 PM) ?

  49. 1-Mar 1:00 PM to 5-Mar 3:00 PM = ???
    Please Formula..

  50. Hi

    How do I calculate with formula the number of hours , e.g. 0800-1700 ?

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)