What are the different date and time types in SQL?
The SQL server comes with various data type formats to store date, time, or date/time in a database. The various data types have their unique functions.
The SQL server has the following date or date/time data types. They are listed alongside their unique characteristics below:
Data Types
- Time: It has the format
hh:mm:ss[.nnnnnnn]and exists in the range00:00:00.0000000through23:59:59.9999999. It also has a100 nanosecondaccuracy, a storage size of 3 to 5 bytes, and a user-defined fractional second precision.
It doesn’t have a time zone offset.
-
Date: It has the format
YYYY-MM-DD, exists in the range0001-01-01through9999-12-31, and has a day accuracy. The date data type has a storage size of 3 bytes. It does not have a user-defined fractional second precision and doesn’t have a time zone offset. -
Smalldatetime:
Smalldatetimehas the formatYYYY-MM-DDhh:mm:ss. It exists in the range1900-01-01through2079-06-06and has a minute accuracy. It has a storage size of 4 bytes, does not have a user-defined fractional second precision, and doesn’t have a time zone offset. -
Datetime: The format for this data type is
YYYY-MM-DDhh:mm:ss[.nnn]. It has the range1753-01-01through9999-12-31and a0.00333secondaccuracy. Its storage size is 8 bytes. It does not have a user-defined fractional second precision and doesn’t have a time zone offset. -
Datetime2: This data type has the format and range of
YYYY-MM-DD hh:mm:ss[.nnnnnnn]and0001-01-01 00:00:00.0000000through9999-12-31 23:59:59.9999999, respectively. It has an accuracy of100 nanosecondsand a storage size of 6 to 8 bytes. It has a user-defined fractional second precision and doesn’t have a time zone offset. -
Datetimeoffset:
Datetimeoffsethas the formatYYYY-MM-DD hh:mm:ss[.nnnnnnn][+|-]hh:mmand a range of0001-01-01 00:00:00.0000000through9999-12-31 23:59:59.9999999 (in UTC). Its accuracy is100 nanosecondsand has a storage size of 8 to 10 bytes. This data type has a user-defined fractional second precision and a time zone offset.