0
$day = date("Y-m-d", strtotime('+1 month', time())) . " " . "$hour" . ":".  "$minute" . ":" . "00" . "$ampm";
	$day->setTimezone(new DateTimeZone('$ftz'));

I have a user enter a time and I want to generate a $day one month ahead of the day the script was called at the time entered

So for example if I entered 5:10pm PST

$day would become "09-14-2010 05:10:00 PM"

and then I want to convert that timezone to EST so everyones is similar and when I do the
day-> settimezone I get this error:

"Fatal error: Call to a member function setTimezone() on a non-object in"

Any ideas whats going wrong? (note $ftz = "America/New_York"; )

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by metalix
0
<?php

//Set date according to formats accepted by strtotime
//Set timezone to use
$day = new DateTime('yyyy-mm-dd', new DateTimeZone('America/New York'));

//Modify to one month in future
$day->modify('+1 month'); 

//Display updated date
echo $day->format('Y-m-d');

This isn't tested. but the date() function in php does not return an object and in your code, $day would actually be a string. This would cause the non-object error.

This updated code should do what you want, but I haven't tested it.

0
<?php

//Set date according to formats accepted by strtotime
//Set timezone to use
$day = new DateTime('yyyy-mm-dd', new DateTimeZone('America/New York'));

//Modify to one month in future
$day->modify('+1 month'); 

//Display updated date
echo $day->format('Y-m-d');

This isn't tested. but the date() function in php does not return an object and in your code, $day would actually be a string. This would cause the non-object error.

This updated code should do what you want, but I haven't tested it.

How about the inputs? $hour, $minute, $ampm? How can I incorporate those?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.