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

8
  • 3
    And your version of SQL Server is...?
    – Kirk Woll
    Apr 24, 2012 at 15:36
  • 3
    You have seen the Date (only) type in SQL 2008? 3 Bytes msdn.microsoft.com/en-us/library/bb630352(v=sql.100).aspx
    – StuartLC
    Apr 24, 2012 at 15:37
  • 2
    What environment are you developing in which is going to be noticeably affected by a few bytes? Apr 24, 2012 at 15:37
  • Ask yourself if you really need to do this optimization? YAGNI
    – Ian
    Apr 24, 2012 at 15:38
  • 2
    as @nonnb said, you should use the DATE datatype then
    – Lamak
    Apr 24, 2012 at 15:41

2 Answers 2

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.

2

Use the 3 byte Date. See Date data type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.