Jump to content

Find End of Week Date (Saturday)


n1concepts

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
https://forums.phpfreaks.com/topic/283001-find-end-of-week-date-saturday/
Share on other sites

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 |
+------------+

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.