Combine date and time

This tutorial shows how to combine a date and time in one cell using an Excel formula or VBA

Example: Combine date and time

Combine date and time

METHOD 1. Combine date and time

EXCEL

=TEXT(B5,"dd/mm/yyyy")&" "&TEXT(C5,"hh:mm:ss")
This formula uses the Excel TEXT function to format the date and time, that are captured in separate cells, into the nominated formats and concatenate the two by using the (&) sign. In this example we have added a space between the date and time by using &" "&.

METHOD 1. Combine date and time using VBA

VBA

Sub Combine_date_and_time()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'combine date and time into one cell
ws.Range("D5") = Application.WorksheetFunction.Text(ws.Range("B5"), "dd/mm/yyyy") & " " & Application.WorksheetFunction.Text(ws.Range("C5"), "hh:mm:ss")

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code.
Date Reference: Select the cell reference that captures the date by changing the cell reference ("B5") in the VBA code.
Time Reference: Select the time reference that captures the time by changing the cell reference ("C5") in the VBA code.
Worksheet Selection: Select the worksheet which captures the date and time, in separate cells, that you want to combine by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.

Explanation about how to combine date and time

EXPLANATION

EXPLANATION

This tutorial shows how to combine a date and time in one cell using an Excel formula or VBA.
Both the Excel formula and VBA use the TEXT function to format the date and time into the nominated formats and concatenate them to return both the date and time in one cell.
FORMULA
=TEXT(date,"dd/mm/yyyy")&" "&TEXT(time,"hh:mm:ss")
ARGUMENTS
date: The date that you want to combine with the time in one cell.
time: The time that you want to combine with the date in one cell.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to add months to a date using an Excel formula and VBA
How to subtract months from a date using Excel formulas and VBA
How to convert number in ddmmyyyy order to date using an Excel formula and VBA
How to convert number in yyyymmdd order to date using an Excel formula and VBA
How to convert a date into a month name using an Excel formula and VBA

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel TEXT function returns a numeric value as text, in a specified format