Salesforce Formula Date to Text

In this Salesforce Tutorial, we will learn the formula to convert Date to Text in Salesforce. Moreover, we will go through the steps using which we can convert Date to Text in Salesforce Lightning and Salesforce Classic.

In Salesforce, there are many scenarios where we need Salesforce Formula Date to Text, such as email templates, visualforce pages, reporting, data validation, etc.

And, in all these situations, we need to convert Date to Text in Salesforce. So, If you want to explore How to Convert Date to Text in Salesforce Lightning and Classic Edition, you have come to the right place.

The following are the topics that we will cover in this Salesforce Tutorial:

  • Salesforce Formula Date to Text
  • Convert Date to Text Formula in Salesforce Lightning
  • Convert Date to Text Formula in Salesforce Classic

Salesforce Formula Date to Text

In Salesforce, to convert the date field to text datatype, we use the Salesforce Date() and Text() functions together.

Here is the syntax to convert date to text in Salesforce:

TEXT(DATE(datefield))
#OR
TEXT(datefield)

In this code, The API name of the datefield we want to convert date to time should be entered for the Date Field. And this formula returns a new date in text format.

Let’s understand it in detail with the help of an example:

Let’s say we want to create a formula that returns only a year but without number place separated with commas. So for this, we will create a formula that converts Year to Text in Salesforce.

Here is the formula for this:

TEXT(YEAR(datefield))

With, this we have learned the Salesforce Formula Date to Text. Now, we will move further and see How to Convert Date to Text Formula in Salesforce Lightning.

Read Extract Year from Date Salesforce Formula

Convert Date to Text Formula in Salesforce Lightning

Here, are the steps to convert Date to Text using the Advance Formula in Salesforce Lightning.

Step 1: Navigate to Salesforce Setup, by clicking on the Setup icon on the upper right side of the page.

Step 2: On the left side of the menu, click on Object Manager.

Salesforce Formula Date to Text
Salesforce Formula Date to Text

Step 3: Search for the object to which we want to convert the Date to Text. Here, I select the Accounts object from the list of objects.

Salesforce Formula Date to Text Example
Salesforce Formula Date to Text Example

Step 4: Click on Fields & Relationships.

Step 5: Then, click on New.

Salesforce Lightning Formula Date to Text
Salesforce Lightning Formula Date to Text

Step 6: Choose the Formula as the field type.

Step 7: To continue, click Next.

Salesforce Lightning Example Formula Date to Text
Salesforce Lightning Example Formula Date to Text

Step 8: Enter a Field Label for the formula, and the Field Name will be automatically populated. Here, I enter Field Label as the Text SLA Date.

Step 9: Choose Text as the Formula Return Type because by default the DATE function displays the result in date format. Then, click Next.

Convert Date to Text Formula in Salesforce Lightning
Convert Date to Text Formula in Salesforce Lightning

Step 10: Enter the Date to Text formula in the Advance Formula editor. Here, is the formula:

TEXT( DATE ( YEAR( SLAExpirationDate__c ), MONTH( SLAExpirationDate__c ), DAY( SLAExpirationDate__c ) ) )
  • In this formula, we extract the date from the custom field called “SLAExpirationDate__c” using the DATE, YEAR, MONTH, and DAY Salesforce functions. But by default, the DATE function returns the result in a date format.
  • To get the result in the text format, we will use the TEXT function with the DATE function.

Step 11: Click Check Syntax to make sure the formula is correct.

Step 12: We can add the Description and Help Text as options, and we can also state how you want to handle the blank field.

Step 13: After that, click Next.

Convert Date to Text Formula in Salesforce Lightning Example
Convert Date to Text Formula in Salesforce Lightning Example

Step 14: Select the appropriate field Level Security and to make it visible to everyone, here we select the Visible checkbox.

Step 15: Select Next.

How to Convert Date to Text Formula in Salesforce Lightning
How to Convert Date to Text Formula in Salesforce Lightning

Step 16: Choose the Page Layout Name, for whom we want to add the formula field.

Step 17: To save the formula field, click Save.

How to Convert Date to Text Formula in Salesforce Lightning Example
Convert Date to Text Formula in Salesforce Lightning Example

We can use the formula field once we’ve created it. Let’s look at an example:

  • Create or Open an account using the SLA Expiration Date value by opening the Accounts object and saving it.
  • After that, click on the Details section, and here the Text SLA Expiry Date field will appear in the text datatype format instead of the date datatype.
Convert Date to Text Formula in Salesforce
Convert Date to Text Formula in Salesforce

As a result, we now know how to use Salesforce Lightning’s advanced formula to convert Date to Text. Next, we’ll look at how to use Salesforce Classic’s advance formula to convert Date to Text.

Convert Date to Text Formula in Salesforce Classic

Here, are the steps to Convert Date to Text using the Advance Formula in Salesforce Classic.

Step 1: From the Salesforce Lightning to open your Salesforce Classic edition. Click on Avtar and click Switch to Salesforce Classic.

Convert Date to Text Formula in Salesforce Classic
Switch to Salesforce Classic

Step 2: Click on the Setup option.

Convert Date to Text Formula in Salesforce Classic Example
Convert Date to Text Formula in Salesforce Classic Example

Step 3: Scroll down to the Build section. Then under Customize, select the object for whom we want to convert Date to Text. Here, I choose the Campaigns from the object list.

Step 4: Click on the dropdown menu and select Fields.

Date to Text Formula in Salesforce Classic
Date to Text Formula in Salesforce Classic

Step 5: As you scroll down the page, click on the New button under Custom Fields & Relationships.

Date to Text Formula in Salesforce Classic Example
Date to Text Formula in Salesforce Classic Example

Step 6: Select the Formula as the field type.

Step 7: Click Next to proceed.

Salesforce Classic Date to Text Formula
Salesforce Classic Date to Text Formula

Step 8: Enter a Field Label for the formula, and the Field Name will be automatically populated. Here, I enter Field Label as the Text Start Date.

Step 9: Choose Text as the Formula Return Type and then click Next.

Salesforce Classic Example Date to Text Formula
Salesforce Classic Example Date to Text Formula

Step 10: Enter the formula to convert the Date to Text in the advance formula editor. The formula is as follows:

TEXT(StartDate)
  • In this formula, we simply pass the custom date field called “StartDate” to the Text function.
  • In return, it displays the date in text format. It converts the date to text and displays it in YYYY-MM-DD format instead of M/D/YYYY format.

Step 11: To verify that the formula is valid, click Check Syntax.

Step 12: We can specify how you want to handle the empty field and include the Description and Help Text optionally.

Step 13: Then, click Next.

Salesforce Classic Convert Date to Text Formula
Salesforce Classic Convert Date to Text Formula

Step 14: Choose the appropriate Field’s Level Security, and then check the box Visible to make it visible to all.

Step 15: Click Next.

Salesforce Classic Convert Date to Text Formula Example
Salesforce Classic Convert Date to Text Formula Example

Step 16: Choose the Page Layout Name for which the formula field is to be added.

Step 17: Click Save to save the formula field.

Convert Date to Text Advance Formula Salesforce
Convert Date to Text Advance Formula Salesforce

Once we’ve defined the formula field, we may use it. Let’s explore an example:

  • Create a new campaign using the Start Date value by opening the Campaigns object and saving it.
  • After that, click on the Details section, and here the Text StartDate field will appear with the date value in the text datatype.
Salesforce Classic Example Date to Text Advance Formula
Salesforce Classic Example Date to Text Advance Formula

In a conclusion, we now understand how to convert Date to Text using Salesforce Classic’s advanced formula.

Also, Read

Conclusion

In conclusion, we have learned the advance salesforce formula to convert Date to Text. Moreover, we have learned that both Salesforce Classic and Salesforce Lightning provide a simple procedure to convert Date to Text.

In addition to this, the following are the topics that we have discussed:

  • Salesforce Formula Date to Text
  • Convert Date to Text Formula in Salesforce Lightning
  • Convert Date to Text Formula in Salesforce Classic