SiKum
SiKum

Reputation: 95

Mysql how to get First Monday of given year and Month

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

Answers (1)

user2208436
user2208436

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

Related Questions