Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql how to get First Monday of given year and Month

Tags:

mysql

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.

like image 306
SiKum Avatar asked Nov 15 '13 13:11

SiKum


1 Answers

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.

like image 143
user2208436 Avatar answered Sep 25 '22 00:09

user2208436