Robert Granlund
asked on
strtotime But Start on Monday
If I have this date 2013-06-09 (Friday September 6th) but I want to calculate strtotime starting on Sunday, 2013-01-09, How would I do that with the following code?
$rd = ' 2013-06-09';
//echo $rd.'<br />';
$pDate = strtotime($rd.' + 1 week');
// BUT I want to start at Sunday, always Sunday no matter what day it is//
$new_date = date('Y-m-d',$pDate);
echo $new_date;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
2013-06-09 <> (Friday September 6th)
2013-06-09 = (Sunday June 9th)
2013-09-06 = (Friday September 6th)
It is extremely rare to see YYYY-DD-MM used
regarding Ray's suggestion above, I believe that will return "the next Sunday (after)" so you may need to then subtract 7 days.
2013-06-09 = (Sunday June 9th)
2013-09-06 = (Friday September 6th)
It is extremely rare to see YYYY-DD-MM used
To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dateshttp://php.net/manual/en/function.strtotime.php
regarding Ray's suggestion above, I believe that will return "the next Sunday (after)" so you may need to then subtract 7 days.
ASKER
Thank you for that link. It was insightful for me.
The rules for strtotime() are pretty stable, but the inputs are worthy of careful testing. Thanks for the points and best of luck with your project, ~Ray
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html