Hello Everyone, In this section we are going to see the procedure of formatting date/datetime in salesforce formula field. There is not any dedicated function present in salesforce to accomplish this task. So here we go for the custom solution. So let's get started,
Date format in salesforce formula field
Following's are the formula that used to set format of date/datetime field in Salesforce.
In Date field
1. Format MM-DD-YYYY
Return type: Text
TEXT(MONTH(Date__c))+ "-" + TEXT(DAY(Date__c))+ "-" + TEXT(YEAR(Date__c))
2. Format YYMMDD
Return type: Text
RIGHT(TEXT(YEAR(Date__c)),2) + "" +LPAD(TEXT(MONTH(Date__c)),2,"0") + "" +LPAD(TEXT(DAY(Date__c)),2,"0")
3. Format YY/MM/DD
Return type: Text
RIGHT(TEXT(YEAR(Date__c)),2) + "/" +LPAD(TEXT(MONTH(Date__c)),2,"0") + "/" +LPAD(TEXT(DAY(Date__c)),2,"0")
In DateTime field
1. Format YYYY-MM-DD
Return type: Text
TEXT(YEAR(DATEVALUE(CreatedDate) ))+ "-" +TEXT(MONTH(DATEVALUE(CreatedDate) ))+ "-" +TEXT(DAY(DATEVALUE(CreatedDate)))
2. Format DD-MM-YYYY
Return type: Text
TEXT(DAY(DATEVALUE(CreatedDate)))+ "-" +TEXT(MONTH(DATEVALUE(CreatedDate) ))+ "-" +TEXT(YEAR(DATEVALUE(CreatedDate)))
3. Format YY/MM/DD
Return type: Text
RIGHT(TEXT(YEAR(DATEVALUE(CreatedDate))),2) + "/" +LPAD(TEXT(MONTH(DATEVALUE(CreatedDate))),2,"0") + "/" +LPAD(TEXT(DAY(DATEVALUE(CreatedDate))),2,"0")
Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
4 Comments
Hi there!
ReplyDeleteThank you for your helpful post - it provided enough info for me to create the formula I needed! My use case required MM/DD/YYYY, so I used "LPAD(TEXT(MONTH(StartDate)),2,"0")+ "/" + LPAD(TEXT(DAY(StartDate)),2,"0")+ "/" + TEXT(YEAR(StartDate)"
This post is decently helpful, but I wanted to point out that In Date Field #1 is returning M-D-YYYY, In DateTime Field #1 is returning YYYY-D-M, and In DateTime Field #2 is returning D-M-YYYY. I also think the Output image was meant to show up in a different location in the post, since it doesn't correspond with In DateTime Field #3
Thanks eleinejames, Glad to see this post proved to be of little help to you
Deletehere What field is this Date__c
ReplyDeleteDate__c is a custom field that i used in formula field, you can pick any date field as per your need.
DeletePost a Comment