Jump to content

catchable fatal error : Object of class DateTime could not be converted to string.


paul_mcdonald

Recommended Posts

I'm doing a conversion of a time between timezones.  The conversion part works fine, however when I go to use the $newtime variable as part of my sql statement I get the following error: catchable fatal error : Object of class DateTime could not be converted to string.

 

Here is my code ... any help is appreciated!:

// code to handle different timezone	
				   $time= $matchtime;
				   $sourceTimezone = new DateTimeZone('America/Halifax');
				   echo "Halifax :: " .$time;
				  
                                   $date = datetime::createFromFormat('H:i', $time, $sourceTimezone);
				   $destinationTimezone = new DateTimeZone('America/St_Johns');
				   $date->setTimezone($destinationTimezone);
				   $newtime=$date->format('H:i');
				  
                                    echo "<br>StJohns :: ".$newtime;		
							  		
		$str = "select * from tbl_schedule
			where B_id = '$id'
				and game_date = '$date' and team1_result <> 'Win'
				and team1_result <> 'Loss' and game_time <= '$newtime'";

"and game_date = '$date' and team1_result  'Win'"
$date is a DateTime object, not a string. You need to do the same kind of thing you did with $newtime: format() the time to get the Y-m-d value and use that in your query instead.

$newdate = $date->format('Y-m-d');
"and game_date = '$newdate' and team1_result  'Win'"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.