paul_mcdonald Posted October 23, 2013 Share Posted October 23, 2013 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'"; Link to comment https://forums.phpfreaks.com/topic/283213-catchable-fatal-error-object-of-class-datetime-could-not-be-converted-to-string/ Share on other sites More sharing options...
requinix Posted October 23, 2013 Share Posted October 23, 2013 "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'" Link to comment https://forums.phpfreaks.com/topic/283213-catchable-fatal-error-object-of-class-datetime-could-not-be-converted-to-string/#findComment-1455110 Share on other sites More sharing options...
paul_mcdonald Posted October 23, 2013 Author Share Posted October 23, 2013 Darn ... I missed the fact that I was already using that $date variable name! Thanks!!!! Link to comment https://forums.phpfreaks.com/topic/283213-catchable-fatal-error-object-of-class-datetime-could-not-be-converted-to-string/#findComment-1455115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.