Question

How can we remove the time in the order created date inside the transactional email?

We now load it like this; {{var created_at_formatted}} and displayed as: 9 apr. 2020 11:17:59

We want to remove the time and change the format to 9 April 2020.

Was it helpful?

Solution

you can use {{trans '%created_at' created_at=$order.getCreatedAtFormatted(3)}}

All possible parameter of getCreatedAtFormatted() are :

/* date/time format types */
const NONE = -1;
const FULL = 0;
const LONG = 1;
const MEDIUM = 2;
const SHORT = 3;

If it doesn't work then override method getCreatedAtFormatted($format) from vendor\magento\modules-sales\model\Order.php ; in your custom module and set $format to 0 when calling it in your mail template.

public function getCreatedAtFormatted($format)
{
return $this->timezone->formatDateTime(
    new \DateTime($this->getCreatedAt()),
    $format,
    $format,
    $this->localeResolver->getDefaultLocale(),
    $this->timezone->getConfigTimezone('store', $this->getStore()),
    'd M Y' // <-------------------- add this   
);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top