Catchable fatal error:

Hello everyone. I have goten this code to work great except for 1 thing so far. Trying to get the dates to output from a DB. All other information will output, but when I add the:
[PHP]

".$result[‘DateEntered’]." ".$result['DateUpdated']."[/PHP]

to the output the program errors out:
Catchable fatal error: Object of class DateTime could not be converted to string in C:\Inetpub\wwwroot\msag\index.php on line 78

The error seems pretty straight forward, however, I am not sure how to handle it.

This is my code thusfar, any suggestions or help would be greatly appreciated.
[PHP]

MSAG Database





<?php include 'includes/menu.php'; ?>

Search Category:

Street Name Low Range High Range OEB ESN Number Community Telco Map Number Entry Date Last Modified

     Search Criteria:

<?php

include ‘includes/db/connect.php’;

if(isset($_POST[‘search’]) || isset($_POST[‘submit’]))
{
$category = $_POST[‘category’];
$criteria = $_POST[‘criteria’];

$query = "SELECT * FROM MSAG WHERE $category LIKE '%$criteria%' ORDER BY StreetName ASC";
$resource=sqlsrv_query($conn, $query) or die(print_r(sqlsrv_errors(), true));

}
?>

<?php

while($result=sqlsrv_fetch_array($resource))
{
echo "

"; } ?>
Prefix Street Name Low Range High Range OEB ESN Number Community Telco Map Number Entry Date Last Modified Details
".$result['StreetPrefix']." ".$result['StreetName']." ".$result['LOWNUMBER']." ".$result['HighNumber']." ".$result['EOB']." ".$result['ESN']." ".$result['COMMUNITY']." ".$result['TELCO']." ".$result['MAP']." ".$result['DateEntered']." ".$result['DateUpdated']."
[/PHP]

I don’t see where you are using a DateTime object but you can convert it to a string using format.

http://www.php.net/manual/en/datetime.format.php

$result[‘DateEntered’]->format(‘Y-m-d H:i:s’)

That is the key. I had been putting the date into a Varchar in the DB forwhatever reason, and I just went in and made that fix so thats what was causing the issue. In case it can help anyone else the code is. Just like mr Matt said. works like a charm. Thank you sir

".$result['DateUpdated'] ->format('m-d-Y') ."
Sponsor our Newsletter | Privacy Policy | Terms of Service