n1concepts Posted October 15, 2013 Share Posted October 15, 2013 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'); Quote Link to comment https://forums.phpfreaks.com/topic/283001-find-end-of-week-date-saturday/ Share on other sites More sharing options...
Solution Barand Posted October 15, 2013 Solution Share Posted October 15, 2013 (edited) 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 October 15, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/283001-find-end-of-week-date-saturday/#findComment-1454071 Share on other sites More sharing options...
n1concepts Posted October 16, 2013 Author Share Posted October 16, 2013 Yep, that worked - appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/283001-find-end-of-week-date-saturday/#findComment-1454111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.