$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)

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

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

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

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);

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.