Calculate the date of last sunday in Mysql?
Posted on 2011-04-28
So Im constructing some queries to generate a weekly leaderboard. I need to be able to select all the records within the current week starting with the previous sunday. The logic is this...
if today is sunday, then just return todays date, if its not sunday return the date of previous sunday
that way I can query like this:
select * from quizhistory where (**SUNDAY CALCULATION** <= startdate) and (startdate < DATE_ADD(**SUNDAY CALCULATION**, INTERVAL 1 WEEK)
I have been trying to figure out how to do this using mysql date time functions but have had no luck thus far.
Working solution is worth 500 points.