Jump to content

Find End of Week Date (Saturday)


n1concepts
Go to solution Solved by Barand,

Recommended Posts

Hi,

 

What is the best MySQL function to find the 'endofweek' DATE similar to using 'LAST-DAY()' function to get end of month date?

SELECT LAST_DAY('2013-10-31')

I am asking of I'm not sure their is a global function for this purpose or if I have to combine server date functions to get result.

Any insight appreciated - thx!

 

Example: CURDATE() - for any date - it will always yield the 'Y-m-d' of that week's date for the following Saturday of that week.

In this case, that would be '2013-10-19' for today '2014-10-15'.

 

Thx!

 

 

SELECT LAST_DAY('2009-05-18');
SELECT LAST_DAY('2009-05-18');
SELECT LAST_DAY('2009-05-18');
Link to comment
Share on other sites

  • Solution

try

$d = new DateTime();  // today by default
$di = DateInterval::createFromDateString("next saturday");
$d->add($di);
echo $d->format('Y-m-d');   // --> 2013-10-19

edit: nm. I just noticed this the is the MySQL forum tab in my browser and not PHP Help

mysql> SELECT '2013-10-15' + INTERVAL 7 - DAYOFWEEK('2013-10-15') DAY as saturday;

+------------+
| saturday   |
+------------+
| 2013-10-19 |
+------------+
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.