Magento How to Format Date in an Email Template

Magento How to Format Date in an Email Template

July 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento How to Format Date in an Email Template

Formatting Dates in Magento Email Templates

Email templates in Magento are critical for maintaining brand consistency and providing essential information to customers. One common requirement is to format dates within these templates. In this post, we’ll explore how to properly format the date output from your email templates.

The Problem with Date Formatting

You’re correct that simply using PHP’s date() function won’t work directly in Magento templates. This is because Magento doesn’t parse standard PHP code during template rendering. Instead, it uses its own variable handling system.

The given code snippet:

Dispatch Date: {{var order.getShippingDate()}}

Simply calls the getShippingDate method on the current order object and displays the result as-is. The output will be in the date format defined by Magento’s core settings, which may not match your desired display.

Formatting Dates Using Magento Functionality

To format dates within email templates, we need to use Magento’s built-in formatDate function. This function allows you to convert a date object into a string using specific formatting rules.

Here’s the syntax:

Dispatch Date: {{var order.getShippingDate() | formatDate: "long"}}

In this example:

  • order is the current order object.
  • getShippingDate() retrieves the shipping date of the order.
  • | formatDate: "long" applies the ‘long’ formatting style to the date.

The formatDate filter supports several styles out-of-the-box, including ‘short’, ‘medium’, and ‘long’. These styles correspond to PHP’s date() function formats like ‘Y-m-d H:i:s’, ‘m/d/Y h:ia’, and ‘F j, Y g:ia’.

Custom Date Formatting

What if you need a date format that isn’t covered by the built-in styles? In this case, you can use the formatDate filter with a custom formatting string.

Here’s an example:

Dispatch Date: {{var order.getShippingDate() | formatDate: "F jS, Y"}}

In this example, we’re using a custom format string that translates to ‘February 1st, 2023’. The available characters and their meanings are the same as in PHP’s date() function.

Incorporating Formatted Dates in Email Content

Remember that formatted dates should be used judiciously. While they can make your emails look more professional, they shouldn’t interfere with the core content or customer experience.

For example, you might include a formatted date in the subject line for tracking purposes:

Subject: Your Order #{{var order.increment_id}} has been shipped - Dispatch Date: {{var order.getShippingDate() | formatDate: "long"}}

Conclusion

Formatting dates in Magento email templates requires understanding how the template engine handles variables. By using the formatDate filter, you can easily convert date objects into strings that meet your display needs.

Remember to test your formatted dates across different customer time zones and languages to ensure they appear correctly. For more advanced customizations or if you’re building a complex email system, consider exploring Magento’s advanced email templates features or even third-party extensions like MageMail for enhanced functionality.

In conclusion, while date formatting in Magento may seem daunting at first, it becomes straightforward once you understand the available tools. With this knowledge, you can create more effective and professional email communications for your customers.

Security Themes Configuration Email

Our network