This article follows post in which I offered overview of Data types in SQL Server (more in SQL Data types – Overview ). You can find list of all system data types in it. We can now focus on another category from mentioned overview of t-sql Date and time data types.
Date data types specification will be shorter than previous article on numeral ones since there is not much to write about. It is simple.
SQL Date and Time Data Types
|Data Type||Range of Values||Format||Size|
|DATE||0001-01-01 to 9999-12-31||YYYY-MM-DD||3 Bytes|
|TIME||00:00:00.0000000 to 23:59:59.9999999||hh:mm:ss[.nnnnnnn]||3-5 Bytes|
|SMALLDATETIME||1900-01-01 to 2079-06-06||YYYY-MM-DD hh:mm:ss||4 Bytes|
|DATETIME||1753-01-01 to 9999-12-31||YYYY-MM-DD hh:mm:ss[.nnn]||8 Bytes|
|DATETIME2||0001-01-01 00:00:00.0000000 to 9999-12-31 23:59:59.9999999||YYYY-MM-DD hh:mm:ss[.nnnnnnn]||6-8 Bytes|
|DATETIMEOFFSET||0001-01-01 00:00:00.0000000 to 9999-12-31 23:59:59.9999999 (UTC)||YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm||8-10 Bytes|
Things to point out:
- Data type DATETIMEOFFSET which enables user to obtain information on time zone. This might be the choice for globally focused databases
- DATETIME can hold dates all the way back to 1753
- SMALLDATETIME holds dates till 1900
More detailed information on date data types can be found on Microsoft web here