Working with time and date in email templates

Sometimes you might want to send to customer in an email also current time and date. The time and date is the server time and date which is set to Mountain Standard Time, specifically America/Phoenix timezone. This article shows you how you can display the time/date in a different timezone than the server timezone or how you can display it in a different format than the default.

This applies to email templates which you can customize under Configuration > Email > Customer Templates or Agent Templates.

The variables that you can use to display the time and date that return the time in the server timezone (America/Phoenix) are:

  • {$time} - displays server time
  • {$date} - displays server date

If you want to show a time that is not the server time (Mountain Standard Time GMT-7) then you can:

{math assign=ParisTime equation="x+y" x=$smarty.now y=28800}
{$ParisTime|date_format:"%d-%m-%Y %H:%M:%S"}

Math expressions cannot be used in rules, only in email templates.

In the above example, a new variable is created with the timestamp for Paris.

The above code reads the actual time, adds 8 hours to it (28800 seconds), and assigns the value to the variable "ParisTime". The variable then can be used anywhere in the text, after the initial math equation.

The new time will be displayed in the format "%d-%m-%Y %H:%M:%S" which outputs something like "30-04-2024 12:24:36".

You can add different time in seconds to get your own timezone, and you can also display the final time in a different format - more info about Smarty date format can be found here.

Time format examples:

  • {$smarty.now|date_format:"%A, %B %e, %Y"} - Monday, April 1, 2024
  • {$smarty.now|date_format:"%H:%M %d.%m.%Y"} - 9:45 25.05.2024
  • {$ParisTime|date_format:"%H:%M %d.%m.%Y"} - 17:45 25.05.2024
×