0
$hour = $_POST['hour'];    
$minute = $_POST['minute'];
$ampm = $_POST['ampm'];  
$tz = $_POST['tz'];
$ftz = "America/New_York";
if($ampm == 'PM')
{
	$hour = $hour + 12;
}

$temptime = strtotime("$hour" . ":".  "$minute" . ":" . "00");





	$tempdate = date('Y-m-d', strtotime('+1 month'));
	$tempval = $tempdate . " " . $temptime;
	$nextalert = new datetime ($tempval, new DateTimeZone('$tz'));
	$nextalert->setTimezone(new DateTimeZone('$ftz'));
	echo $nextalert ;

In my test: hour = 05 minutes= 00 seconds = 00 PM Timezone = PDT

The error I am getting

Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct() [<a href='datetimezone.--construct'>datetimezone.--construct</a>]: Unknown or bad timezone ($tz)'

I want the date output to be: 2010-9-16 14:00:00 EDT (3 hour pdt > edt conversion)

Edited by dwssassin: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dwssassin
0

It's the single quotes around the variable $tz.

new DateTimeZone('$tz')
// should be
new DateTimeZone("$tz")
0

That worked but now I cannot insert it into the SQL database because I get the following error:

Catchable fatal error: Object of class DateTime could not be converted to string
0

It doesn't seem that class datetime has a __toString() method. But it does have a format() method. Try that with an appropriate date format for your database.

For mysql, this looks promising...

echo $nextalert.format(DateTime::ISO8601);
0

What I am basically trying to do is take a string time from a html form: 2010-9-16 14:00:00 EDT convert that into a time -> Convert that time zone -> convert that back to a string I can place in my sql table.

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.