Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a date in VisualForce?

In Salesforce, if I'm binding a date into a VisualForce page, how do I apply custom formatting to it?

Example:

<apex:page standardController="Contact">   <apex:pageBlock title="Test">       <p>{!contact.Birthdate}</p>   </apex:pageBlock>                      <apex:detail relatedList="false" /> </apex:page>  

This will output a date in the default format:

Thu Jul 01 09:10:23 GMT 2009

How do I get it (for example) into dd/mm/yyyy format, like this:

01/07/2009

(Hopefully this is a fairly easy question, but to get the Salesforce community going on here I figure we need a few easy questions.)

like image 764
codeulike Avatar asked Mar 25 '10 14:03

codeulike


People also ask

How do I display a date in dd mm yyyy format in Salesforce?

TEXT( DAY(Date Field)) & “/” & TEXT(MONTH(Date Field)) & “/”& TEXT(YEAR(Date Field)). This field will store the text version of Date Field in dd/mm/yyyy format.

How do I display the current date in visualforce?

Visualforce has Data and Time functions too, you can use {! NOW()} or {! TODAY()}.

What is Apex Param?

<apex:param> tag is used to pass values from JavaScript to an Apex controller,it can only be used with the folloing parent tags.


1 Answers

<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">     <apex:param value="{!contact.Birthdate}" />  </apex:outputText> 

link to full doc: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm

like image 62
Ryan Guest Avatar answered Oct 12 '22 12:10

Ryan Guest