Danijel Andjelkovic Fri Jul 13 11:27:31 -0400 2012

Subject: DateTime could not be converted to string

I am trying to display content of table 'page' which contains one timestamp field with Page::find('all').
When I want to echo the result of this column I get folowing error: Message: Object of class ActiveRecord\DateTime could not be converted to string.

Thanka you,

Chris R Wed Jul 18 10:14:04 -0400 2012

Hi Danijel,

For DATETIME fields, PHP Activerecord will return an ActiveRecord\DateTime object.

In order to display this as a string, you should call the 'format' method. For example, if the DATETIME field is called created_at, you can do:

$page->created_at->format('Y-m-d H:i:s');

You can make your own display format using standard PHP date formatting: