SQL Server Concat Date and Time into DateTime

In this article, I’ll walk you through everything you need to know about how to concat date and time into datetime in SQL Server. I’ll cover multiple methods, explain their pros and cons, and provide practical examples you can use right away.

SQL Server Concat Date and Time into DateTime

Before diving into the how, let’s understand the why:

  • Data Storage Efficiency: Storing date and time separately can be inefficient and complicate queries.
  • Simplified Queries: Combining into one datetime column simplifies filtering and calculations.
  • Reporting & Analytics: Most reporting tools expect a single datetime field.
  • Avoiding Errors: Combining properly avoids rounding or truncation errors.

Method 1: Using CAST and CONVERT with String Concatenation

One straightforward way is to convert both date and time to strings, concatenate them, then cast back to datetime.

SELECT
CAST(CONVERT(varchar(10), EventDate, 120) + ' ' + CONVERT(varchar(8), EventTime, 108) AS datetime) AS CombinedDateTime
FROM DateTimeSeparate;
  • CONVERT(varchar(10), YourDateColumn, 120) Converts date to YYYY-MM-DD.
  • CONVERT(varchar(8), YourTimeColumn, 108) converts time to HH:MM:SS.
  • Concatenate with a space in between.
  • Cast the concatenated string back to datetime.

After executing the above query, I got the expected output as shown in the screenshot below.

SQL Server Concat Date and Time into DateTime

Pros:

  • Simple to understand and implement.
  • Works well for SQL Server 2008 and later.

Cons:

  • Involves implicit conversions and string manipulation, which may affect performance on large datasets.

Method 2: Using DATEADD with DATEDIFF

This method adds the time portion as seconds (or milliseconds) to the date.

SELECT
    DATEADD(SECOND, DATEDIFF(SECOND, 0, EventTime), CAST(EventDate AS datetime)) AS CombinedDateTime
FROM DateTimeSeparate;

Explanation:

  • DATEDIFF(SECOND, 0, YourTimeColumn) calculates the number of seconds since midnight.
  • DATEADD(SECOND, ..., YourDateColumn) adds those seconds to the date.

After executing the above query, I got the expected output as shown in the screenshot below.

Combine Date and Time into DateTime SQL

Pros:

  • Avoids string manipulation.
  • Efficient and precise.

Cons:

  • Works best if the time precision is to the second.

For higher precision (milliseconds or microseconds), adjust the units accordingly.

Method 3: Using DATETIME2 and Arithmetic

If your columns are date and time, You can cast both to datetime2 and add:

declare @dc date = '2025-08-08'
declare @tc time(7) = '23:59:59.9999999'

select cast(concat(@dc, ' ', @tc) as datetime2(7))

After executing the above query, I got the expected output as shown in the screenshot below.

SQL Concat Date and Time into DateTime

Method 4: Using DATETIMEFROMPARTS (SQL Server 2012+)

If you want to build a datetime from components explicitly:

SELECT
    DATETIMEFROMPARTS(
        YEAR(EventDate),
        MONTH(EventDate),
        DAY(EventDate),
        DATEPART(HOUR, EventTime),
        DATEPART(MINUTE, EventTime),
        DATEPART(SECOND, EventTime),
        DATEPART(MILLISECOND, EventTime)
    ) AS CombinedDateTime
FROM DateTimeSeparate;

After executing the above query, I got the expected output as shown in the screenshot below.

how to concat date and time

Pros:

  • Very explicit and precise.
  • Avoids any implicit conversions.

Cons:

  • Verbose.
  • Only available in SQL Server 2012+.

Performance Comparison of Methods

If you’re working with large datasets, performance matters. Here’s a quick overview:

MethodPerformancePrecisionSQL Server Version
CAST + CONVERT (string concat)ModerateSeconds2008+
DATEADD + DATEDIFF (numeric)FastSeconds2008+
CAST + CAST (datetime2 addition)FastHigh (100ns)2008+
DATETIMEFROMPARTSModerateHigh2012+

Practical Example: Combining Appointment Date and Time

Let’s say you have a table called Appointments with columns:

AppointmentDate (date)AppointmentTime (time)
2025-08-0614:30:00
2025-08-0709:15:30

You want to create a DateTime column that combines these.

Using Method 1 (CAST + CONVERT):

SELECT
    Appointment_date,
    Appointment_time,
    CAST(CONVERT(varchar(10), Appointment_date, 120) + ' ' + CONVERT(varchar(8), Appointment_time, 108) AS datetime) AS AppointmentDateTime
FROM Appointment_schedule;

After executing the above query, I got the expected output as shown in the screenshot below.

Add Time To Date in sql server

Using Method 2 (DATEADD + DATEDIFF):

SELECT
    AppointmentDate,
    AppointmentTime,
    DATEADD(SECOND, DATEDIFF(SECOND, 0, AppointmentTime), CAST(AppointmentDate AS datetime)) AS AppointmentDateTime
FROM Appointments;

After executing the above query, I got the expected output as shown in the screenshot below.

sql join date to datetime

Tips for Working with Date and Time in SQL Server

  • Always be aware of the data types you are working with.
  • Use datetime2 for better precision and a wider range.
  • Avoid unnecessary string conversions for performance.
  • Test your queries with edge cases like midnight (00:00:00) and end of day (23:59:59.999).
  • When working with time zones, consider using datetimeoffset.

Summary Table of Methods

MethodSyntax ExampleBest Use Case
String Concatenation + CASTCAST(CONVERT(varchar, date) + ' ' + CONVERT(varchar, time) AS datetime)Quick and easy, legacy support
DATEADD + DATEDIFFDATEADD(SECOND, DATEDIFF(SECOND, 0, time), CAST(date AS datetime))Performance-sensitive, seconds precision
Add CASTed datetime2CAST(date AS datetime2) + CAST(time AS datetime2)High precision, clean syntax
DATETIMEFROMPARTSDATETIMEFROMPARTS(YEAR(date), MONTH(date), DAY(date), HOUR(time), MINUTE(time), SECOND(time), MILLISECOND(time))Explicit component building, SQL 2012+

Video Tutorial

Final Thoughts

Combining date and time into a datetime value in SQL Server is a common but sometimes tricky task. The right method depends on your SQL Server version, precision requirements, and performance considerations.

For most modern applications, It is recommended to use casting to datetime2 and adding the values for precision and simplicity. If you need compatibility with older versions or simpler syntax, string concatenation or DATEADD Methods work well.

You may also like the following articles.