See how getCreatedAtFormatted
is declared:
public function getCreatedAtFormatted($format)
{
return $this->timezone->formatDateTime(
new \DateTime($this->getCreatedAt()),
$format,
$format,
null,
$this->timezone->getConfigTimezone('store', $this->getStore())
);
}
It uses $this->getCreatedAt()
to create DateTime
and if you create DateTime
like new \DateTime(null)
you get current date.
The above means that if you have no value for created_at
data of order, you are still going to get valid \DateTime
object.
This is why getCreatedAtFormatted
works and getCreatedAt
is not.
Now all you need to figure out is why order is lacking created at value.
My guess is, that created_at
is added by a timestamp update in the table, and to get its value, you may need to call $order->load($order->getId())
getCreatedAtFormatted
usesgetCreatedAt
to create DateTime instance. So ifgetCreatedAt
returnsnull
and that is passed togetCreatedAtFormatted
, then you are just getting current day's date not order created_at date. – Petar Dzhambazov Apr 19 '16 at 8:04null
? – Toan Nguyen Apr 19 '16 at 8:09