0

I am trying to store my date in the format 'YYMM' / 'YY-MM' as date type without conversion, as I only need the year and month. Solutions I've searched online are mostly by conversion like Cast etc. Was wondering if it is possible to configure it from the datatype in the database table like Date(1, 1). Thanks!

lalalaa
  • 21
  • 1
  • 4
  • 3
    store dates as dates not strings! Doing otherwise is a recipe for pain! – Mitch Wheat Nov 08 '16 at 04:52
  • please visit site Different [way of store month and year](http://dba.stackexchange.com/questions/14800/best-pratice-to-store-dates-group-by-months-year-key-par-value) .it's help you – Rajshee Turakhia Nov 08 '16 at 05:25
  • please visit site http://dba.stackexchange.com/questions/14800/best-pratice-to-store-dates-group-by-months-year-key-par-value it's help you – Rajshee Turakhia Nov 08 '16 at 05:26
  • [Bad habits to kick : choosing the wrong data type](https://sqlblog.org/2009/10/12/bad-habits-to-kick-choosing-the-wrong-data-type) - you should always use the most appropriate data type - that's what they're there for, after all! – marc_s Nov 08 '16 at 05:43

2 Answers2

0

I'd store it as a std date type and just ignore the day.

If that's not suitable, I'd have two columns, 1 byte each, Year and Month.

tymtam
  • 31,798
  • 8
  • 86
  • 126
-1

you can store year and month like this.

Declare    @a    Char(6)
Set        @a =  Getdate()
Select     @a
Husen
  • 1,541
  • 10
  • 14