We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Calculate the date of last sunday in Mysql?

richardsimnett
on
Medium Priority
3,101 Views
Last Modified: 2015-07-22
Hello,
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.

Thanks,
Rick
Comment
Watch Question

Senior Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Perfect!
Hi Walter,

The above query which you mentioned will work for below case also right?

if today is sunday, then just return todays date, if its not sunday return the date of previous sunday
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.