Loading

Render Date fields in a certain format in Visualforce HTML email templates

Date de publication: Jun 14, 2026
Description

When creating a Visualforce HTML email template and including a Date field (not a DateTime field) using a merge field such as {!relatedTo.Custom_Date__c}, the date renders with full timestamp and timezone information in the following format:
Mon Oct 22 00:00:00 GMT 2018
If you need the date to display in a clean format such as DD/MM/YYYY, without time or timezone information, you must use Visualforce formula functions to extract and format the individual date components. Note that this applies specifically to Date fields — DateTime fields have different rendering behavior.

Résolution

Use the DAY(), MONTH(), YEAR(), and CASE() Visualforce formula functions to extract and format the date components from the Date field. The CASE() function is used to zero-pad single-digit month numbers.
The following formula renders a Date field in DD/MM/YYYY format. Replace VFDateTest__c with your actual Date field API name:

{!DAY(relatedTo.VFDateTest__c)}/{!CASE(MONTH(relatedTo.VFDateTest__c),1,"01/",2,"02/",3,"03/",4,"04/",5,"05/",6,"06/",7,"07/",8,"08/",9,"09/",10,"10/",11,"11/",12,"12/","??/")}{!YEAR(relatedTo.VFDateTest__c)}

How this formula works:

  • DAY(...) extracts the numeric day of the month.
  • CASE(MONTH(...), ...) maps each month number to a zero-padded two-digit string followed by a slash.
  • YEAR(...) extracts the four-digit year.
  • The result is a string in DD/MM/YYYY format, for example: 05/03/2024.
Numéro d’article de la base de connaissances

000385770

 
Chargement
Salesforce Help | Article