PHP Syntax Error

What is wrong with the following PHP?
If my url is:
Why does the following not work?
if ((isset($_GET['d']))) {
	$rd = $_GET['d'];
	$requestDate = date($rd, strtotime("+2 weeks"));
	echo '<h1>NEW DATE: '.$requestDate.'</h1>';

Open in new window

it always echo's; 2013-09-08
There is something wrong with the way I am formatting:
$requestDate = date($rd, strtotime("+2 weeks"));
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The first parameter to date() is the date format. So in this case, you're basically saying:
$requestDate = date("2013-09-08", strtotime("+2 weeks"));

Open in new window

Since you don't have any variables like "Y" or "m" in the date format parameter, you end up with the literal string of "2013-09-08" instead of a formatted date value.

I think you are probably thinking more along the lines of:
// Get the timestamp of the parameter passed in
$fromDate = strtotime($rd);  

// Calculate two weeks from that date
$twoWeeks = strtotime("+2 weeks", $fromDate); 

// Generate the YYYY-MM-DD date string for that calculated date
$requestDate = date("Y-m-d", $twoWeeks); 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi there,

The explanations given to you by gr8gonzo are right.

However, you can do it in another way, using a DateTime object:
  if ((isset($_GET['d']))) {
    $rd = $_GET['d'];
    $d1 = new DateTime($rd);   // create the DateTime object
    date_modify($d1, "+2 weeks");   // changing the value of the object created
    $requestDate = date_format($d1, "Y-m-d");   // extracting a formatted string 
    echo '<h1>NEW DATE: '.$requestDate.'</h1>'; // publishing the string value

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.