Finding the Week of the Month using MySQL

Recently for a project I needed to be able to query when something was at least a day old and wanted to make sure that I updated the item every month on the first wednesday. I wanted to utilize mysql to query those that I needed and was able to find another blog’s entry on how to do that – the following is the code needed to retrieve the day of the week for the specified date:

SELECT WEEK(my_date_field,5) -
WEEK(DATE_SUB(my_date_field, INTERVAL DAYOFMONTH(my_date_field)-1 DAY),5)+1

Thanks go to:

Tuesday, March 2nd, 2010 MySQL

Leave a Reply

You must be logged in to post a comment.

[ad code=1 align=center]