tags:

views:

76

answers:

2

I have an SQL timestamp field and I need to group it by month like

Jan, Feb, Mar, ... but in numbers (01, 02, 03, ...)

I've tried

GROUP BY DATE_FORMAT(i.push_date, '%Y-%m')

But it's not working.

A: 
GROUP BY YEAR(i.push_date), MONTH(i.push_date)
Greg
+2  A: 

Try to use the Month() method.

Select Month(<field>) from <table> group by Month(<column>);

what you get back will be the month in number form. You might to group by month and year which would be:

Select Year(<column), Month(<field>) from <table> group by Month(<column>), Year(<column>);

Date/Time Functions for MySql

CSharpAtl