Salesforce Formula to Calculate Days Between Dates : Bijay Kumar

Salesforce Formula to Calculate Days Between Dates
by: Bijay Kumar
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary The content is a tutorial on how to calculate the number of days between two dates in Salesforce using a formula field. This process can be done both in Salesforce Classic and Salesforce Lightning. The tutorial presents a step-by-step guide for creating a formula that subtracts one date from another to obtain the difference in days. #### Key Points: 1. **Purpose**: The task involves calculating days between two dates in Salesforce. 2. **Formula**: To find the number of days, you can use the formula: - `EndDateField - StartDateField` - or - `DATEVALUE(EndDateField) - DATEVALUE(StartDateField)` (for Date and Time fields). 3. **Example Context**: For instance, determining how many days it takes for a lead to convert into an opportunity. 4. **Steps in Salesforce Lightning**: - Access Setup > Object Manager. - Choose the relevant object (e.g., Orders). - Create a new formula field (e.g., Delivery Days). - Use the formula to calculate the day difference (e.g., `Expected_Delivery_Date__c - EffectiveDate`). - Adjust field visibility and save the field. 5. **Outcome**: The new field will display the difference in days when checking the order details. ### Additional Context Calculating date differences in Salesforce is essential for tracking performance metrics and understanding timelines in projects, sales cycles, and customer interactions. The provided examples and formulas can improve efficiency in managing records and analyzing business processes. ### Hashtags for SEO #Salesforce #SalesforceTutorial #DateCalculation #SalesforceLightning #FormulaField #CRM #DataManagement #SalesforceTips #SalesforceDevelopment #TechTutorials


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.
    • Select Object Manager from the nav bar.
Formula for Number of Days Between Dates in Salesforce
  1. Look for the object whose field you wish to get the days between dates. In this instance, I chose the Orders object from the list of objects.
Formula to calculate Days between two Dates in Salesforce Lightning
  1. Select Fields & Relationships. Next, select New.
Salesforce Formula for Number of Days Between Dates
  1. Select Formula as the field type. Click Next to proceed.
Salesforce Advance Formula for Number of Days Between Dates
  1. After entering a Field Label for the formula, the Field Name will be filled in automatically. Here, I specify the field label as Delivery Days.
    • Select the Formula Return Type as Number and also set the Decimal Places to Zero. After that, select Next.
Calculate Days between two Dates in Salesforce Lightning
  1. In the Advanced Formula editor, enter the advanced formula to determine the Days between two Dates. The formula is as follows:
Expected_Delivery_Date__c -  EffectiveDate 
  • In this example, we aim to determine the number of days between the Expected Delivery Date and the Order Start Date.
  • Therefore, we subtract the Effective Date from the Expected Delivery Date fields.
  1. To verify that the formula is valid, click Check Syntax.
    • We can specify how you want to handle the empty field and include the Description and Help Text as optional fields.
    • Then, select Next.
Salesforce Formula to Calculate Days Between Dates
Days between two Dates in Salesforce Lightning Example
  1. Select the appropriate field’s level of security, and then check the box beside ‘Visible’ to make it visible to everyone. Click Next.
Formula to calculate Days between two Dates in Salesforce Lightning Example
  1. Select the Page Layout Name for which the formula field is to be stated. Click Save to save the formula field.
Calculate Days between two Dates in Salesforce Lightning Example
  1. Once we’ve set up the formula field, we may use it. Let’s examine an example:
    • Open up the Orders Tab and create an order with an Expected Delivery Date and Start Order Date, and save it.
    • After that, click on the Details section, and the Delivery Days field will appear, showing the difference between the two Dates.
Days between two Dates in Salesforce Lightning

Conclusion

We now know how to calculate the number of days between dates using the advanced Salesforce formula.

Furthermore, we discovered that there is a formula to get the days between dates using both Salesforce Classic and Salesforce Lightning.

You may like to read:

The post Salesforce Formula to Calculate Days Between Dates appeared first on SalesForce FAQs.


September 11, 2025 at 06:30PM
Click here for more details...

=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce