$order->dateOrdered returns a string value the first time and DateTime after that. [Order got through event] I am using the Commerce 2 plugin and I am experiencing a very odd issue. Once an order is complete I want to use the dateOrdered property to create a csv which I send through a request endpoint. That worked fine.

BUT! Since recently (somewhere this month), on the first attempt to create and save the .csv, when calling $order-&gt;dateOrdered-&gt;getTimestamp() I get dateOrdered as a string.

On the second attempt to create and save the .csv I get dateOrdered as a DateTime.

The method which I am calling is the same so I think it has something to do wiht order statuses. 

I tried to trace the problem in Commerce's Order.php class but I still have no clue why this occurs or what I am doing wrong.

Any help is more than welcome. Thank you in advance!
The problem was occurring because the order was retrieved through the EVENT_AFTER_ORDER_PAID event. Therefore, the dateOrdered was still not processed (passed through mutations). 

What we ended up doing is using $event-&gt;sender only to know what order we are looking for and then retrieve the order anew.

I hope this saves someone's life someday! I'll mark this question as solved in 2 days.