Neta Meta Neta Meta - 5 months ago 22
PHP Question

Working with podio api, i get a DateTime object and cant access its values

i make an API call for Podio, to get active space members. One of the fields that returns is

last_seen_on
, which is a
DateTime
Object.

When i
print_r()
it looks like:

DateTime Object
(
[date] => 2013-11-02 22:47:09
[timezone_type] => 3
[timezone] => UTC
)


The issue is when I get the
date
or
timezone_type
or
timezone
by doing
$object[date]
, or
$object->date
it throws an error.

Now i am not sure if this has something to do with php DateTime class, if so.. how do I use that object with that class?

Answer

As it's a datetime instance, you can return the date with the following. Or however you want, in accordance to the documentation.

echo $object->format('Y-m-d H:i:s');

Link to documentation