0

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! :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180

2 Answers2

5

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.

Darren Kopp
  • 76,581
  • 9
  • 79
  • 93
2

Use the 3 byte Date. See Date data type

Jamiec
  • 133,658
  • 13
  • 134
  • 193
htoverkill
  • 89
  • 7