0

I have an object that looks like this:

Foo_Transaction Object (
    [_attributes] => Array (
            [id] => abcdefg
            [orderId] => 
            [createdAt] => DateTime Object (
                    [date] => 2015-03-05 18:57:48.000000
                )

I can access id with $result->transaction->id just fine.

However, trying to access the date data with $result->transaction->createdAt->date returns NULL. Am I doing it wrong?

2 Answers 2

3

It's a DateTime object so you need to use DateTime::format() to get that date value as a string:

echo $result->transaction->createdAt->format('Y-m-d H:i:s');
Sign up to request clarification or add additional context in comments.

Comments

3

Because createdAt is a DateTime PHP object. To get this date as a string:

$result->transaction->createdAt->format('Y-m-d H:i:s')

See the documentation of the date() function for the accepted date formatting parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.