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
tgganeshtgganesh 

Date format

Hi All,

 

I want to display a date field in VisualForce Email template.

According to user locale language selection.. the date format should get change.

If an user is from US... date should display in MM/DD/YYYY format

For UK user date should display in DD/MM/YYYY format..

 

if am using {!Now()} in template... date format is changing according to locale.

 

I tried by giving the date field directly and am receiving the output "Thu Feb 23 00:00:00 GMT 2012."

 

I tried  {!day(relatedTo.Datefield__c)}/{!month(relatedTo.Datefield__c)}/{!year(relatedTo.Datefield__c)}, here i have defined the format.. so its not getting change according to the locale...

 

Give me an idea to display date format according to the locale of user.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
tgganeshtgganesh

Hi All,

 

I found a solution for my prob... i need to display the date format according to language that i select.

 

i created custom label and mentioned the format in that..

 

using <apex:outputtext tag and <apex:param tag, i resolved my prob.

 

Eg:

 

Cutome label :EmailText

Language - English (UK)

 

Hi all,

 

My date format {2}/{3}/{4}

 

Email Template:

 

<apex:outputText value="{!$Label.EmailText}" escape="false">
    <apex:param value="{!DAY(relatedTo.Email_Date__c)}"/>
    <apex:param value="{!MONTH(relatedTo.Email_Date__c)}"/>
    <apex:param value="{!TEXT(YEAR(relatedTo.Email_Date__c))}"/>

 

Output:

Hi all,

 

My date format 08/03/2012

 

 

We can add different format for different language in a single custom label.

Thus it works :)

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Here you can make use of format () method

 

Format (): Returns a Date time as a string using the supplied Java simple date format and time zone.

This example i have made use of locale as. (Dot) format

system.debug('@@@@@@@@@@@@@@@'+system.now());

system.debug('*****************'+system.now().format());

output:

@@@@@@@@@@@@@@@2012-02-23 05:34:00

*****************22.2.2012 21:34

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

Chamil MadusankaChamil Madusanka

Try this approach

 

http://stackoverflow.com/questions/2516549/how-to-format-a-date-in-visualforce

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

tgganeshtgganesh

Hi All,

 

I found a solution for my prob... i need to display the date format according to language that i select.

 

i created custom label and mentioned the format in that..

 

using <apex:outputtext tag and <apex:param tag, i resolved my prob.

 

Eg:

 

Cutome label :EmailText

Language - English (UK)

 

Hi all,

 

My date format {2}/{3}/{4}

 

Email Template:

 

<apex:outputText value="{!$Label.EmailText}" escape="false">
    <apex:param value="{!DAY(relatedTo.Email_Date__c)}"/>
    <apex:param value="{!MONTH(relatedTo.Email_Date__c)}"/>
    <apex:param value="{!TEXT(YEAR(relatedTo.Email_Date__c))}"/>

 

Output:

Hi all,

 

My date format 08/03/2012

 

 

We can add different format for different language in a single custom label.

Thus it works :)

This was selected as the best answer