MySQL: select date of current week's monday

If you need date of monday in current week try this:

SELECT DATE_ADD(CURDATE(), INTERVAL - WEEKDAY(CURDATE()) DAY)

It return you monday date of current week.


In fact, DATE_ADD is not necessary and complicates the logic. Here is the simplest version for "Date of the first day of the current week":

select date(curdate() - interval weekday(curdate()) day)

which would translate to: get the date() part of the (current date - an interval of N days) where N = today's number in the week, i.e. Thu is number 3 (for a week starting on Monday)

Then, getting the Monday of previous week, is:

select date(curdate() - interval weekday(curdate()) day - interval 1 week)

which is more readable IMHO.


For thhose who need the Monday date of the current week.

If you count Monday as the first day of the week:

SELECT STR_TO_DATE(CONCAT(YEARWEEK(NOW(), 1),'Monday'), '%x%v %W');

If you count Sunday as the first day of the week:

SELECT STR_TO_DATE(CONCAT(YEARWEEK(NOW()),'Monday'), '%X%V %W');

Tags:

Mysql