Search code examples
phpmysqldatejoomla

How to get next week monday to sunday in my sql


I am using below code for fetching next monday but i am unable to fetch next sunday on same week. like today is friday and if i search next week then i need to get next week monday to sunday.

SELECT now() + INTERVAL 7 - weekday(now()) DAY 

This above give me next monday.

I need to add 7 more days and get sunday date in same format.

2018-07-30 14:45:43 Monday

2018-08-05 14:45:43 Sunday


Solution

  • Add 6 days to get the sunday of the monday. Add 13 days to add the second sunday after the monday:

    SELECT (now() + INTERVAL 7 - weekday(now()) DAY) + INTERVAL 6 DAY;