How should I store year? as Int or Char(4) ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    How should I store year? as Int or Char(4) ?

    I've always stored year (like of a vehicles make or a home's built year) as an int.

    What datatype do you use to store a 4 or 2 digit year?

    I like int for comparison reasons.

    Let me know your thoughts. Easy question right? :)





    Dan
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    I would most likely use the YEAR type. It's only a single byte and can store years between 1901-2155.
    If that doesn't work for some reason, I would go with a SMALLINT. It's twice as big as YEAR, but it can store a much larger range.

    I would never use Char(4) though. It's just... wrong :)

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      hmmm YEAR type. I guess that's better than INT since I can use the date functions more flawlessly with them too.

      INT is way too large.

      Good Advice From Experts as Always!



      Dan

      Comment

      Working...