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
ajitvermaajitverma 

Format Date On VF Page

Hi All,

i need to display related list of opportunities on visual force page with "created date" field. I am using Account as StandardController for the page.
My issue is regarding the format of CreatedDate field, by default it shows the value with time stamp but the desired format is 'dd/mm/yyyy'.
how can i change its format on Visual force page directly.


Thanks
Ajit Verma
Best Answer chosen by Admin (Salesforce Developers) 
David VPDavid VP
Using VF only you can use formulas to achieve this:

Code:
{!DAY(dt)}/{!MONTH(dt)}/{!YEAR(dt)}

 
... your formatting will then of course be hard coded and will not adapt to local settings.



-David

All Answers

David VPDavid VP
Using VF only you can use formulas to achieve this:

Code:
{!DAY(dt)}/{!MONTH(dt)}/{!YEAR(dt)}

 
... your formatting will then of course be hard coded and will not adapt to local settings.



-David
This was selected as the best answer
ajitvermaajitverma
Hi David,

i tried it on my vf page but it's not working.
i am getting error
Syntax error. Missing ')' . In vf page i am using                 <apex:column value="{!MONTH(Opp.CreatedDate)}"/>.



Thanks

Ajit



MayeUPAEPMayeUPAEP

Hi ajitverma,

Try This:

 

<apex:column headerValue="Date">{!DAY(Opp.CreatedDate)}/{!MONTH(Opp.CreatedDate)}/{!YEAR(Opp.CreatedDate)}</apex:column>

 

 

rangaranga

thanks it works fine

David Roberts 4David Roberts 4
Thanks. Worked for me, too, using a wrapper within a simple <table> for exporting to excel.

Here's a snippet:

<apex:repeat value="{!wr.retsLicences}" var="wl">
          <tr>
          <td>{!wl.Name}</td>
          <td>{!wl.Active__c}</td>
          <td>{!DAY(wl.Maintenance_Expires__c)}/{!MONTH(wl.Maintenance_Expires__c)}/{!YEAR(wl.Maintenance_Expires__c)}</td>
          </tr>
</apex:repeat>