# Catchable fatal error:

**URL:** <https://www.phphelp.com/t/catchable-fatal-error/18956>\
**Category:** General PHP Help\
**Created:** [November 21, 2012, 5:04pm UTC](https://www.phphelp.com/t/catchable-fatal-error/18956 "2012-11-21T17:04:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![willscarlet](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@willscarlet](https://www.phphelp.com/u/willscarlet)\
**Post date:** [November 21, 2012, 5:04pm UTC](https://www.phphelp.com/t/catchable-fatal-error/18956/1 "2012-11-21T17:04:06Z")

</div>

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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]

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [November 21, 2012, 7:37pm UTC](https://www.phphelp.com/t/catchable-fatal-error/18956/2 "2012-11-21T19:37:09Z")

</div>

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](http://www.php.net/manual/en/datetime.format.php)

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

---

<div class="post-metadata">

**Author:** ![willscarlet](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@willscarlet](https://www.phphelp.com/u/willscarlet)\
**Post date:** [November 21, 2012, 7:42pm UTC](https://www.phphelp.com/t/catchable-fatal-error/18956/3 "2012-11-21T19:42:08Z")

</div>

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') ."
