how to get the Month and Year from date

I want to extract MONTH-YEAR out of the date (datetime format)

Please advice how to do it...

Thanks in advance
redgreenredAsked:
Who is Participating?
 
chapmandewConnect With a Mentor Commented:
whoops...

select month(datefield), year(datefield)
from yourtable
0
 
powercramCommented:
In what context?
0
 
chapmandewCommented:
select mont(datefield), year(datefield)
from yourtable
0
 
lluddenCommented:
You can also use DATEPART to get any piece of a datetime value:

SELECT DATEPART(datepart,date)
where datepart is:

Datepart Abbreviations 
year     yy, yyyy 
quarter  qq, q 
month    mm, m 
dayofyear dy, y 
day      dd, d 
week     wk, ww 
weekday  dw 
hour     hh 
minute   mi, n 
second   ss, s 
millisecond ms 

Open in new window

0
 
cpleong99Connect With a Mentor Commented:

select cast(month(datefield) as varchar(2)) + '-' + cast(year(datefield) as varchar(4))
from table1

this will return Month-Year
0
All Courses

From novice to tech pro — start learning today.