Anatoly Lubarsky Logo
MSSQL, .NET, Design. Life and Music

MSSQL 2008: What is DATETIME2

MSSQL 2008 introduces several new DATETIME datatypes for T-SQL. It is obvious that TIME and DATE provide the ability to store separately DATE and TIME parts of DATETIME. It was not possible to do in previous versions of MSSQL, however it was possible to get either part of the DATETIME using DATETIME functions, for example a couple of years ago I posted about how to Get only Date from DateTime.


  • TIME
  • DATE
  • DATETIME2
  • DATETIMEOFFSET

What is DATETIME2 ? It is an improved version of DATETIME. It we compare between them:


  • Storage: DATETIME2 takes 6-8 bytes, DATETIME takes 8 bytes.
  • Accuracy: DATETIME2 (100 nanosec), DATETIME (333 nanosec).
  • Range: DATETIME2 (0001/01/01 - 9999/12/31), DATETIME (1753/01/01 - 9999/12/31).

Sounds cool. Except strange name used for the datatype...(LOL) Seems like folks in Microsoft copied VARCHAR2 convention from Oracle which I didn't understand either.


DATETIMEOFFSET datatype is like DATETIME2 plus in addition it can store TIMEZONE in hh:mm while the actual datetime is stored in UTC. This datatype takes up to 10 bytes in storage however.


EDIT: There are also new system functions introduced: SYSDATETIME(), SYSUTCDATETIME(). Both return system time AS DATETIME2. And also SYSDATETIMEOFFSET() which returns system time as DATETIMEOFFSET.


HTH


Related Posts:

Tuesday, May 13, 2008 7:13 PM

Comments

# MSSQL 2008: Spatial Data Types - Geography and Geometry
In addition to new DATETIME data types introduced in MSSQL 2008 there are geography and geometry data types introduced - useful for storing and manipulating geodetic data. Geometry data type is used to store flat map data like points, lines, and shapes [ ... ]

5/14/2008 5:28 PM by Anatoly Lubarsky

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)