Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

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;

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PortletPaul
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
To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates
http://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.
Avatar of Robert Granlund

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