Convert DateTime to Date Salesforce

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

While working in an organization that uses Salesforce as a CRM tool, I got a task where I needed to perform an operation on the date portion of the datetime field. So, to fulfill this requirement, I use the Convert DateTime to Date functionality of Salesforce.

If you want to learn How to Convert DateTime to Date using Salesforce Lightning and Salesforce Classic, you have come to the right place.

The following are the topics that we will cover in this salesforce tutorial:

  • Convert DateTime to Date
  • How to Convert DateTime to Date in Salesforce Lightning
  • How to Convert DateTime to Date in Salesforce Classic

Convert DateTime to Date

In Salesforce, Datetime, and Date are different data types. We can use them interchangeably. To perform any operations or comparisons on Date and Datetime values, we always need to convert them to the same data type.

So, to convert datetime field to a date field using the advance formula, we use the DATEVALUE function of Salesforce.

Here, is the syntax to convert DateTime to Date in Salesforce:

DATEVALUE(datetimefield)

If, you want to learn in detail about DATEVALUE() function, read Date Formula Functions in Salesforce.

How to Convert DateTime to Date in Salesforce Lightning

Here, are the steps to convert DateTime to Date 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.

Convert DateTime to Date in Salesforce
Convert DateTime to Date in Salesforce

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

Salesforce Convert DateTime to Date
Salesforce Convert DateTime to Date

Step 4: Click on Fields & Relationships.

Step 5: Then, click on New.

Salesforce Example Convert DateTime to Date
Salesforce Example Convert DateTime to Date

Step 6: Choose the Formula as the field type.

Step 7: To continue, click Next.

Convert DateTime to Date in Salesforce Lightning
Convert DateTime to Date in Salesforce Lightning

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

Step 9: Choose Date as the Formula Return Type. Then, click Next.

Convert DateTime to Date in Salesforce Lightning Example
Convert DateTime to Date in Salesforce Lightning Example

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

DATEVALUE(CancellationDate)
  • In this formula, we convert the datetime field called “CancellationDate” to the date field using the DATEVALUE Salesforce 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.

How to Convert DateTime to Date in Salesforce Lightning
Convert DateTime to Date in Salesforce Lightning Advance Formula

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 DateTime to Date in Salesforce Lightning Example
Convert DateTime to Date in Salesforce Lightning Example

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.

DateTime to Date in Salesforce Lightning
DateTime to Date in Salesforce Lightning

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

  • Create Payments with Cancellation Date value field by opening the Payments object and saving it.
  • After that, click on the Details section, and here the Cancel Pay Date field will appear in the date data type format instead of the datetime data type.
DateTime to Date in Salesforce Lightning Example
DateTime to Date in Salesforce Lightning Example

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

Read Salesforce Formula Date to Text

How to Convert DateTime to Date in Salesforce Classic

Here, are the steps to Convert DateTime to Date 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.

How to Convert DateTime to Date in Salesforce Classic
Switch to Salesforce Classic

Step 2: Click on the Setup option.

How to Convert DateTime to Date in Salesforce Classic Example
Convert DateTime to Date in Salesforce Classic Example

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

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

Convert DateTime to Date in Salesforce Classic
Convert DateTime to Date in Salesforce Classic

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

Convert DateTime to Date in Salesforce Classic Example
Convert DateTime to Date in Salesforce Classic Example

Step 6: Select the Formula as the field type.

Step 7: Click Next to proceed.

DateTime to Date in Salesforce Classic
DateTime to Date in Salesforce Classic

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

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

DateTime to Date in Salesforce Classic Example
DateTime to Date in Salesforce Classic Example

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

DATEVALUE(CreatedDate)

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 DateTime to Date Formula
Salesforce Classic DateTime to Date 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 DateTime to Date Formula Example
Salesforce Classic DateTime to Date 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.

Salesforce Classic Example DateTime to Date
Salesforce Classic Example DateTime to Date

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

  • Create a new case with the Entitlement Process Start Time field value by opening the cases object and saving it.
  • After that, click on the Details section, and here the Process Start Date field will appear in the date data type format instead of the datetime data type.
Salesforce Classic DateTime to Date Advance Formula
Salesforce Classic DateTime to Date Advance Formula

We now understand how to convert DateTime to Date using Salesforce Classic’s advanced formula.

Also, Read

Conclusion

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

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

  • Convert DateTime to Date
  • How to Convert DateTime to Date in Salesforce Lightning
  • How to Convert DateTime to Date in Salesforce Classic