MSSQLTips.com · March 15, 2023
Working with Date and Time Data Types in SQL Server
This tutorial compares the six SQL Server data types used to represent dates and times: DATE, DATETIME, DATETIME2, SMALLDATETIME, DATETIMEOFFSET and TIME. Examples illustrate their different precision, storage requirements and supported representations, including fractional seconds and UTC offsets. It also distinguishes the TIMESTAMP or ROWVERSION data type from temporal values.
The article examines behavioral differences between DATETIME and DATETIME2, including date arithmetic and implicit conversions, and discusses potential query estimation issues. A final example demonstrates converting Excel serial date numbers to SQL Server dates while accounting for Excel’s historical leap-year convention.