I'm currently making a making a visualforce email template and I'm having a problem with displaying the desired output format.

I have a field, Opportunity.Start_DateTime__c with DatetTime format.

Ex. 3/02/2017 9:55 PM

How do I display it as Friday 3rd February 2017 and 03 Feb 2017 9:55 PM?

So far I tried these:

input1 : <apex:outputText value="{!cx.Opportunity.Start_Date_Time__c}"/>

output1: Fri Feb 03 10:55:00 GMT 2017 (don't need the GST one)

input2 : <apex:outputText value="{!DATETIMEVALUE(cx.Opportunity.Start_Date_Time__c)}"/>

output2: 3/02/2017 9:55 PM (correct data / incorrect format)


<apex:outputText value="- {0,date,dd MMM yyyy hh:mm a}"> 
                            <apex:param value="{!DATETIMEVALUE(cx.Opportunity.Start_Date_Time__c)}" />

output3: 03 Feb 2017 10:55 AM (correct format but don't need GST one)

Really need this...Thanks in advance !

  • you want it in current user's timezone? – Raul Feb 6 '17 at 12:11
  • @rahul I just want to show it as it is saved in salesforce like my example. – Micz Domz Feb 7 '17 at 1:04

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:outputText value="{0, date,EEEE d MMMM yyyy}">
                    <apex:param value="{!contact.CreatedDate}" /> 
                <apex:outputText value="{0, date,d MMMM yyyy HH:mm a}">
                    <apex:param value="{!contact.CreatedDate}" /> 

Varioous DateTime formatting

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.

| improve this answer | |
  • Just one correction, MMMM - will February for current month instead of Feb (for which use 3 M's) – Raul Feb 6 '17 at 12:27
  • Thanks @RahulSharma, abbreviation pattern is replicated with the EEEE. – TSmith Feb 6 '17 at 14:21
  • OP asked in Visualforce Email Template not Visualforce page. For Visualforce email template it will be {!relatedTo.CreatedDate} instead – compski Nov 28 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.