Wednesday, August 10, 2011

MySQL get Start(Sunday) and End(Saturday) of week for a given date

select subdate(date('2011-08-06'), INTERVAL dayofweek(date('2011-08-06')) DAY) as StartOfWeek, adddate(date('2011-08-06'), INTERVAL 7-dayofweek(date('2011-08-06')) DAY) as EndOfWeek;
select subdate(date('2011-08-07'), INTERVAL dayofweek(date('2011-08-07')) DAY) as StartOfWeek, adddate(date('2011-08-07'), INTERVAL 7-dayofweek(date('2011-08-07')) DAY) as EndOfWeek;
select subdate(date('2011-08-13'), INTERVAL dayofweek(date('2011-08-13')) DAY) as StartOfWeek, adddate(date('2011-08-13'), INTERVAL 7-dayofweek(date('2011-08-13')) DAY) as EndOfWeek;

No comments: