Daud Ahmad Daud Ahmad -5 years ago 169
SQL Question

Get month and year from a datetime in SQL Server 2005

I need the month+year from the datetime in SQL Server like 'Jan 2008'. I'm grouping the query by month, year. I've searched and found functions like datepart, convert, etc., but none of them seem useful for this. Am I missing something here? Is there a function for this?

Answer Source

If you mean you want them back as a string, in that format;

  CONVERT(CHAR(4), date_of_birth, 100) + CONVERT(CHAR(4), date_of_birth, 120) 
FROM customers

Here are the other format options

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download