Reputation: 95
How to get the first monday of given year month.
SET @YearMonth:= '201304';
Result:
2013-04-01 (For April)
2013-11-04 (For November)
Thanks in advance.
Upvotes: 7
Views: 7745
Reputation: 389
Try this
SET @firstday = '2013-04-01';
SELECT ADDDATE( @firstday , MOD((9-DAYOFWEEK(@firstday)),7)) as first_monday;
The param @firstday is the first day of the month you want to search. Note that sunday is the first day of a week, monday is the second day.
Upvotes: 8