In MySQL, how to return the week of the month?

Use the MySQL built-in function week to find the week number for the year, then subtract the week number for the first day of the month.

SELECT WEEK('2012-02-20') - WEEK('2012-02-01')

there are plenty of options in the documentation to customize the call to fit exactly what you are looking for, but I hope my example gives you an idea of what is available to you.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week


FLOOR((DayOfMonth(dateCol)-1)/7)+1

I'd like to make it clear that this is probably not a good way to divide your data - (see the comments), but that this will get you as close as you can get.

Tags:

Mysql