So let's say
WEEK(Date,1)
returns 32, how do I get it to give me date of the Monday of that week, so that it returns 2017-08-07?
So let's say
WEEK(Date,1)
returns 32, how do I get it to give me date of the Monday of that week, so that it returns 2017-08-07?
select if(weekday('2017-08-05') != 0, 
case 
when weekday('2017-08-05') =6 then date_sub('2017-08-05', interval 6     
day) 
when weekday('2017-08-05') =5 then date_sub('2017-08-05', interval 5     
day)
when weekday('2017-08-05') =4 then date_sub('2017-08-05', interval 4     
day)
when weekday('2017-08-05') =3 then date_sub('2017-08-05', interval 3 
day)
when weekday('2017-08-05') =2 then date_sub('2017-08-05', interval 2 
day)
when weekday('2017-08-05') =1 then date_sub('2017-08-05', interval 1 
day) end,'2017-08-05') as Date_of_Monday;
Shall give you the date of 'Monday' of the week of the Date you give as input
For the above query,
I gave input as 2017-08-05 and it gave the result as 2017-07-31 which is the Monday of the week the date 2017-08-05 falls in.