SOLVED

Formula for adding time

Iron Contributor

How to make an addition of time in Excel minutes and hours I believe hours are easy because you just need to sum all the numbers but how about minutes I want to track my time if I have already 8 hours of work per day.

 

I want to input the task then Excel will compute the minute :) so is there a specific formula for this?

4 Replies
best response confirmed by gmj12345 (Iron Contributor)
Solution

@gmj12345 

u have two options for adding time in Excel, depending on whether you want to:

1. Add multiple existing times:

In this case, you can simply use the SUM function. Excel treats times as fractions of a day, so adding them together will automatically combine hours and minutes.

For example, let's say you have the following times in cells A1 and A2:

  • A1: 8:30 AM
  • A2: 7:15 AM

To find the total time, enter the following formula in cell A3:

Excel
=SUM(A1, A2)
 

This will display the result as 15:45, which is the sum of the two times.

2. Add a specific duration to a time:

If you want to add a specific duration (e.g., 30 minutes, 1 hour) to an existing time, you can use the TIME function along with addition.

For example, let's say you have a start time in cell B1 (e.g., 9:00 AM) and want to calculate the end time after adding 1 hour and 30 minutes. You can use the following formula in cell B2:

Excel
=B1 + TIME(1, 30, 0)
 

This formula breaks down the additional duration into hours (1), minutes (30), and seconds (0) and adds it to the start time in cell B1. The result will be displayed as 10:30 AM.

Additional tip:

  • To ensure your cells display the total time correctly, even if it exceeds 24 hours, format the cells as [h]:mm:ss. This will display the time in hours, minutes, and seconds format.

By using these methods, you can easily add time in Excel and track your work hours effectively.

the time(0,0,0) work just change the cell formatting then all is OK :)

A quick follow-up let's see I want to make it cooler I input details in cell A3 with a value say 15 minutes then I want cell B3 to be the one to record the matter how will cell B3 know if the input value in cell A3 is an hour, minute, seconds?

 

Aside from making a multiple column to input different units of time 

 

Sample

gmj12345_0-1708593467089.png

Any other way in making that?

 

@gmj12345 

Based on the information you've provided and the image you sent, here are two approaches to achieve your desired functionality in Excel:

Method 1: Using Text to Columns and Formulas

  1. Convert input to text:

    • In cell A3, enter the time value as text (e.g., "15 minutes").
  2. Split text into components:

    • In cell B3, use the TEXTSPLIT function (available in Excel 365) to separate the value and unit:
    Excel
    =TEXTSPLIT(A3, " ", 2)
     

    This extracts two parts: the number (before the space) and the unit (after the space).

  3. Convert unit to hours:

    • In cell C3, use an IF statement to convert the unit to hours based on the extracted value:
    Excel
    =IF(B3="minutes", B2/60, IF(B3="seconds", B2/3600, B2))
     

    This checks the unit in B3 and applies the appropriate conversion factor:

    • Minutes: Divide by 60 to convert to hours.
    • Seconds: Divide by 3600 to convert to hours.
    • Otherwise, leave the value unchanged (assuming it's already in hours).

Method 2: Using VBA Macro

  1. Create a macro:

    • Go to the Developer tab (if not visible, enable it in the File > Options > Customize Ribbon).
    • Click Insert > Module.
  2. Add the following VBA code:

    VBA
    Function ConvertTime(timeValue As String) As Double
        Dim parts As Variant
        parts = Split(timeValue, " ")
        Select Case LCase(parts(1))
            Case "minutes"
                ConvertTime = Val(parts(0)) / 60
            Case "seconds"
                ConvertTime = Val(parts(0)) / 3600
            Case Else
                ConvertTime = Val(parts(0))
        End Select
    End Function
     
  3. Use the function in cell B3:

    Excel
    =ConvertTime(A3)
     

Explanation:

  • Method 1: This approach leverages Excel formulas to split the text input, extract the unit, and perform the conversion based on the unit.
  • Method 2: This method uses a VBA macro to define a custom function ConvertTime that handles the separation, unit conversion, and returns the result in hours.

Choosing the method:

  • Method 1 is simpler if you're comfortable with formulas and don't require extensive automation.
  • Method 2 offers more flexibility and can be adapted for more complex scenarios but requires VBA knowledge.

Additional considerations:

  • Ensure consistent formatting of the input time values (e.g., always include the unit).
  • You can modify the formulas or macro to accommodate different units (e.g., days) if needed.
  • Consider error handling in case of invalid input formats.

By implementing one of these methods, you can achieve the desired functionality of automatically converting user-entered time values with units (minutes, seconds) to hours in Excel,

1 best response

Accepted Solutions
best response confirmed by gmj12345 (Iron Contributor)
Solution

@gmj12345 

u have two options for adding time in Excel, depending on whether you want to:

1. Add multiple existing times:

In this case, you can simply use the SUM function. Excel treats times as fractions of a day, so adding them together will automatically combine hours and minutes.

For example, let's say you have the following times in cells A1 and A2:

  • A1: 8:30 AM
  • A2: 7:15 AM

To find the total time, enter the following formula in cell A3:

Excel
=SUM(A1, A2)
 

This will display the result as 15:45, which is the sum of the two times.

2. Add a specific duration to a time:

If you want to add a specific duration (e.g., 30 minutes, 1 hour) to an existing time, you can use the TIME function along with addition.

For example, let's say you have a start time in cell B1 (e.g., 9:00 AM) and want to calculate the end time after adding 1 hour and 30 minutes. You can use the following formula in cell B2:

Excel
=B1 + TIME(1, 30, 0)
 

This formula breaks down the additional duration into hours (1), minutes (30), and seconds (0) and adds it to the start time in cell B1. The result will be displayed as 10:30 AM.

Additional tip:

  • To ensure your cells display the total time correctly, even if it exceeds 24 hours, format the cells as [h]:mm:ss. This will display the time in hours, minutes, and seconds format.

By using these methods, you can easily add time in Excel and track your work hours effectively.

View solution in original post