function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Victoria RileyVictoria Riley 

Change date format in visualforce email

I am trying to change my date format to mm/dd/yy Here is my code (I bolded the line that contains the date):

<messaging:emailTemplate subject="Reserve Your Buy a Day" recipientType="Contact" relatedToType="Opportunity">
    <messaging:htmlEmailBody >
        <body style="font-family: 'Trebuchet MS'">
            <h2>
                Opportunity with Products</h2>
            <hr style="border: solid thin #0099CC" />
            <br />
            <table cellpadding="5" style="border-collapse: collapse" width="100%">
                <tr>
                    <td align="right" 
                        style="border-right-style: solid; border-right-width: thick; border-right-color: #0099CC;" 
                        width="20%">
                        <i>Name</i>
                    </td>
                    <td width="80%">
                        <b>{!relatedTo.Name}</b>
                    </td>
                </tr>
                <tr>
                    <td align="right" 
                        style="border-right-style: solid; border-right-width: thick; border-right-color: #0099CC;" 
                        width="20%">
                        <i>Amount</i>
                    </td>
                    <td width="80%">
                        <b>{!relatedTo.Amount}</b>
                    </td>
                </tr>

           
            </table>
            <br />
            <table cellpadding="5" style="border-collapse: collapse" width="100%">
                <tr>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>In Memory or Honor</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Date Reserved</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Name of Recognition</b>
                    </td>
                </tr>
                <apex:repeat value="{!relatedTo.OpportunityLineItems}" var="lineItem">
                        <tr>
                            <td>
                                {!lineItem.Donation_Type__c}
                            </td>
                            <td>
                                {!lineItem.Calendar_Day_Reserved__c}
                            </td>
                            <td>
                                {!lineItem.Name_of_Recognition__c}
                            </td>
                            <td>
                            </td>                                                            
                        </tr>
                </apex:repeat>
            </table>
        </body>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>
Best Answer chosen by Victoria Riley
Ayush TripathiAyush Tripathi
Hi Victoria 
Use this code inside your <td></td> tags
 
<apex:outputText value="{0,date,MM/dd/yy}"> 
            <apex:param value="{!lineItem.Calender_Day_Reserved__c}" /> 
 </apex:outputText>

 

All Answers

Ayush TripathiAyush Tripathi
Hi Victoria 
Use this code inside your <td></td> tags
 
<apex:outputText value="{0,date,MM/dd/yy}"> 
            <apex:param value="{!lineItem.Calender_Day_Reserved__c}" /> 
 </apex:outputText>

 
This was selected as the best answer
Victoria RileyVictoria Riley
I inserted the code and received the following error message:
User-added image


Here is a screenshot of the opportunity product fields:

User-added image
Ayush TripathiAyush Tripathi
oops the spelling of the calendar is wrong my fault I wrote it "Calender" Please copy the api name and change it
Victoria RileyVictoria Riley
That worked, but the format of the date is still off. Any suggestions:

User-added image
Ayush TripathiAyush Tripathi
I think something else is getting printed along with the date as you can see the date as 2 3"01/19/17". As this is the pattern for the mm/dd/yy.Please see your code again as I see there are only 3 heading while there are 4 <td> tags in the value section
Victoria RileyVictoria Riley
That was it!  Thanks for your help!
Ayush TripathiAyush Tripathi
Thats great.. Mark this thread as closed please