I have added a field called Desired Ship Date on to my email template. when I tested the email template the Desired Ship Date is being shown in the following format "Desired Ship Date: Thu Sep 29 00:00:00 GMT 2016 " but I need it to be displayed in different format like "Desired Ship Date: Thu Sep 29 2016 ". Is there a way I can do it. If yes, Can you let me know how.
[SalesForce] Changing date format on the email template
Related Solutions
I have created some Visualforce markup to demonstrate how we can display different DateTime formats for the Contact CreatedDate. Documenation on the formatting can be found at Salesforces date formatting documentation.
Here is the entire markup being used and its results showing:
<apex:page standardController="Contact">
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockSectionItem>
<apex:outputText value="{0, date,EEEE d MMMM yyyy}">
<apex:param value="{!contact.CreatedDate}" />
</apex:outputText>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputText value="{0, date,d MMMM yyyy HH:mm a}">
<apex:param value="{!contact.CreatedDate}" />
</apex:outputText>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Using "{0, date,EEEE d MMMM yyyy}"
we can display day in text / day / month / year. EEEE is taken from the Java Docs for SimpleDateFormat and provides us with the Day unabbreviated. If you need the day abbreviated please use EEE as explained in those docs.
The second formatting technique we use eliminates the displaying of the day in text and rearranges the date format. We use the letter a to display AM/PM as documented in Pauls SF Blog on Formatting Time in APEX
Hope this helps.
Visualforce email template is available in Lightning, but you can't create a new VF template directly from lightning. for that, you have to use classic email templates setup.
You can use same Classic email templates Text, Custom HTML, Letterhead, and Visualforce email templates in Lightning Experience.
To edit Classic email templates, use Classic Email Templates in Setup.
When you need to insert an email template, change the filter to Classic Email Templates.
for further info: https://help.salesforce.com/articleView?id=classic_templates_in_lightning.htm&type=5
https://help.salesforce.com/articleView?id=classic_templates_in_lightning_considerations.htm&type=5
Best Answer
The best bet is to use
<apex:outputField />
to display your value. This will use the User's date preferences for formatting. If you cannot use that because you are not working with an sObject, see this: Visualforce Date formatting