SQL Sever extract year and month from datetime

Hi,

How to extract year and month from datetime.
I need it to group rows by month so i need to cut day and time part.

MS SQL Server or better SQL server Compact
lavitzAsked:
Who is Participating?
 
LowfatspreadConnect With a Mentor Commented:
convert(char(6),yourdate,112)   as YYYYMM
0
 
BurniePCommented:

select year(getdate()), month(getdate())
0
 
xav056Commented:
Year(getdate())  ,month(getdate())

group by Year(getdate(),Month(getDate())
0
 
sarabhaiCommented:
Sql server provides datetime function for extracting year and month from datetime field.

select year(datetimefield) AS YEAR, month(datetimefiled) AS MONTH FROM TABLE

but here performance may go down,
it is better to do have year and month field with your table having default values  year(datetimefield) and  month(datetimefiled).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.