SQLTeam.com | Weblogs | Forums

Extract only year and month from Date

sql2008

#1

Hi, how can I convert my date column '2010-08-01' to '2010-08', only keeping year and month part. Thank you!


#2

If you need a string with the hyphen:

convert(varchar(7),yourdate,120)

If you need an integer:

datepart(year,yourdate)*100+datepart(month,yourdate)