Salesforce Formula to Calculate Days Between Dates

I was assigned a task at work that required me to calculate the number of days between two dates in Salesforce. To fulfill this requirement, I created a formula field and used an advanced formula to display the number of days.

In this Salesforce Tutorial, we will learn the formula to calculate the number of days between two dates in Salesforce. Additionally, we will review how to utilize Salesforce Lightning to estimate the number of days between two dates.

Salesforce Formula for Number of Days Between Dates

In Salesforce, there are many scenarios where we need to determine the number of days between two dates. For this, we will find the difference between two date values in the number format by subtracting one date from the other.

Here is the general advance formula for the number of days between dates in Salesforce:

EndDateField - StartDateField
                              #OR
DATEVALUE(EndDateField) - DATEVALUE(StartDateField)

Here, we subtract the StartDateField from the EndDateField to calculate the difference between these two dates.

If we have a Date and Time field and want to calculate only the days between two Dates, we use the DATEVALUE function. This function converts the date and time values to the date value.

Let’s understand this with the help of an example:

Suppose we want to calculate the number of days it takes for a lead to convert into an opportunity. To do this, we will calculate the number of days between the lead creation date and the lead conversion date in Salesforce.

Formula to Calculate Days Between Dates in Salesforce

To calculate the number of days between two dates in Salesforce Lightning, the following are the steps that we use:

  1. Click the Setup icon in the top right corner of the page to access Salesforce Setup.
      <