Adding Hours, Minutes, or Seconds to a Date and Time in Excel

This post will guide you how to add hours, minutes, or seconds to a given date and time in a cell in Excel. How do I add hours, minutes or seconds to a time with a formula in Excel. How to add hours to a date and time in Excel. How do I add 15 minutes to a time in excel.

1. Adding Hours to a Date and Time using Formula

If you want to add 2 hours to a specific date and time in one cell, you can use the following formula to achieve the result.

=B1+ 2/24 

You need to type this formula into a blank cell and then press Enter key in your keyboard, and drag the AutoFill Handle over other cells to apply this formula to add 2 hours for other dates.

adding dates1

This formula will return a serial number, so you need to format the serial number as the standard date and time format.

2. Adding Hours to a Date and Time using VBA Code

If you want to use a more dynamic and programmable solution, VBA code is here to assist.

Open the VBA editor by pressing Alt + F11.

In the VBA editor, right-click in the Project Explorer, select Insert, and choose Module to create a new module.

Copy and paste the provided VBA code into the module.

Function AddHoursToDateTime(dateTimeCell As Range, hoursToAdd As Double) As Date
    AddHoursToDateTime = dateTimeCell.Value + hoursToAdd / 24
End Function

This code defines a custom function AddHoursToDateTime to add hours to a date and time.

Return to your Excel sheet and leverage the custom function

Type this formula in a black cell:

=AddHoursToDateTime(B1, 2)

Adjust the reference (B1 in this example) and the hours as needed.

3. Adding Minutes to a Date and Time using formula

If you want to add 15 minutes to a date and time in one cell, you can use the following formula:

=B1 + 15/1440

adding dates2

4. Adding Minutes to a Date and Time using VBA Code

For those seeking a more dynamic and automated approach, let’s explore VBA code for adding minutes.

Open the VBA editor by pressing Alt + F11.

In the VBA editor, right-click in the Project Explorer, select Insert, and choose Module to create a new module.

Copy and paste the provided VBA code into the module.

Function AddMinutesToDateTime(dateTimeCell As Range, minutesToAdd As Double) As Date
    AddMinutesToDateTime = dateTimeCell.Value + minutesToAdd / (24 * 60)
End Function

This code defines a custom function AddMinutesToDateTime to add minutes to a date and time.

Return to your Excel sheet and leverage the custom function, in one black cell type this formula:

=AddMinutesToDateTime(A1, 30)

Adjust the reference (A1 in this example) and the minutes as needed.

5. Adding Seconds to a Date and Time using formula

If you want to add 1 second to a date and time in one cell, you can use the following formula:

=B1 + 1/18640
adding dates3

You can also create another formula based on the TIME function to achieve the same result.
For example, you want to add 2 hours, 15 minutes, 1 second to a data and time value in Cell B1, you can use the following formula:

=B1 + TIME(2,15,1)
adding dates4

6. Adding Seconds to a Date and Time using VBA Code

For those who crave dynamic control over their time-related tasks, VBA code provides the necessary flexibility.

Open the VBA editor by pressing Alt + F11.

In the VBA editor, right-click in the Project Explorer, select Insert, and choose Module to create a new module.

Copy and paste the provided VBA code into the module.

Function AddSecondsToDateTime(dateTime As Date, seconds As Integer) As Date
    AddSecondsToDateTime = dateTime + TimeValue("00:00:" & seconds)
End Function

This code defines a custom function AddSecondsToDateTime to add seconds to a date and time.

Return to your Excel sheet and utilize the custom function:

=AddSecondsToDateTime(A1, 45)

Adjust the reference (A1 in this example) and the seconds as needed.

7. Video: Adding Hours, Minutes, or Seconds to a Date and Time

This Excel video tutorial where we’ll explore efficient ways to manipulate date and time by adding hours, minutes, and seconds. We’ll dive into two methods for each operation: one utilizing formulas and the other harnessing the power of VBA code.

https://youtu.be/OPlsy8xD-GE

Leave a Reply