• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

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

0
rgranlund
Asked:
rgranlund
  • 3
1 Solution
 
Ray PaseurCommented:
<?php // RAY_temp_rgranlund.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28233144.html#a39472019

// CHOOSE WHATEVER IS CORRECT HERE
date_default_timezone_set('UTC');

$rd = ' 2013-06-09';

$new = date('r', strtotime($rd . ' Sunday'));
echo $new;

Open in new window

0
 
PortletPaulfreelancerCommented:
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.
0
 
rgranlundAuthor Commented:
Thank you for that link.  It was insightful for me.
0
 
Ray PaseurCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now