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.