Randolph West continues his SQL Server date & time data types series:
SQL Server 2008 introduced new data types to handle dates and times in a more intelligent way than the
DATETIME
andSMALLDATETIME
types that we looked at previously.This week, we look at the
DATETIME2
data type. I’m not the first person to think that this was probably not the best name for a data type, but here we are, a decade later.
DATETIME2
is, at its heart, a combination of theDATE
andTIME
data types we covered in previous weeks.DATE
is 3 bytes long andTIME
is between 3 and 5 bytes long depending on accuracy. This of course means thatDATETIME2
can be anything from 6 to 8 bytes in length.
Nowadays, if you want to store a date plus time, this should be your default, not DATETIME
.