Error: Object of class DateTime cannot be converted to string

I am getting the error:

$thedate = $row2['date'];
echo $thedate;

      

In php which is the value from the database ($ thedate) is "2015-05-05 21: 52: 31.000"

How can I format it to display it as a string in a php page? It is currently showing the error "Object of class DateTime cannot be converted to string".

+3


source to share


1 answer


You have an object DateTime

, so you need to use format()

to format the output like



echo $thedate->format("Y-m-d");

      

+5


source







All Articles