Format date in email via theme

Hi,

I want to send an email to my users if someone has tried to login to their account and used the wrong password. By default, the base theme adds the time of the failed attempt to the email text (event.date), but the format is hard to read by regular users, for example Wed Sep 25 13:08:02 GMT 2024.

Is there a function I can use to format the date given to the email template?
In case of the email verification mail, there’s the function linkExpirationFormatter(linkExpiration) that formats the time remaining.

You can try these options: Built-ins for date/time/date-time values - Apache FreeMarker Manual
These are all built-ins in Freemarker, so you don’t have to provide any extension.

1 Like

Thank you very much, this helped me solving my problem.

This is how I solved it:

${kcSanitize(msg("eventLoginErrorBodyHtml", event.date?string("dd.MM.yyyy"), event.date?string("HH:mm"), event.ipAddress))?no_esc}

In the eventLoginErrorBodyHtml variable I use the date and time in the text as needed.

2 Likes