Question

DateTime is accurate to three-hundredths of a second. SmallDateTime is accurate to one minute.

What if you only need accuracy to a day? What is the best practice here? I realise that a DateTime is 8 bytes, and SmallDateTime is only 4; but I am just wondering is there a better or more suitable way to store only a date value than creating a column of SmallDateTime and saving SmallDateTime.Date in it ?

Every little helps! :)

Was it helpful?

Solution

It depends on what version of SQL Server you are running.

  • 2008+: Date
  • 2008-: SmallDateTime

Although, if you look at the documentation for smalldatetime, they use a two-byte integer for date and two-byte integer for time, so you could likely replicate their behavior and just store a two-byte integer (smallint) and then use DateAdd to add the number of days since 1900/1/1 if size is really that important in this scenario.

OTHER TIPS

Use the 3 byte Date. See Date data type

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top