Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing just Month and Year in SQL Server 2008?

Is it possible to save the month/year in SQL Server 2008 with a regular datetime? I don't need a time stamp and the column is going to store unique mo/yr combinations (i.e. 10-11, 11-11, 12-11, etc,.).

Any recommendations?

like image 496
genxgeek Avatar asked Oct 20 '11 23:10

genxgeek


1 Answers

Without knowing the intended use, it is not possible to advise correctly. However, storing month and year is easily done in at least three ways:

  • use a date field, but always store into it the first day of the month at midnight; then always custom format the date field for display
  • add integer year and month fields, and populate them by splitting a date
  • add an integer field where you encode it as year * 100 + month or some other useful scheme
like image 93
wallyk Avatar answered Oct 06 '22 10:10

wallyk