Converting Between Date & Time Data Types in SQL Server (T-SQL Examples)

When you convert between date and time data types in SQL Server, you need to be mindful of how the new data type will handle the value you’re trying to assign to it.

In some cases you might lose part of the value, in other cases you might gain a bunch of zeros (increasing storage size in the process). You may also end up with a value that’s been rounded up.

The following articles contain examples of conversions between the different date and time data types, with a particular focus on the issues I just mentioned.

Convert ‘datetime’ to …

Convert ‘datetime2’ to …

Convert ‘datetimeoffset’ to …

Convert ‘smalldatetime’ to …

Convert ‘date’ to …

Convert ‘time’ to …