Salesforce Due Date Formula: Calculate Due Dates with Examples

When I was working as a Salesforce Admin in a company, they wanted to set a Payment Due Date on every Invoice record automatically.

They wanted the Due Date to be 30 days after the Invoice Date. Instead of asking users to enter the due date manually each time, I created a formula field in Salesforce that calculated it automatically.

In this Salesforce tutorial, we will learn the Salesforce Due Date Formula. Additionally, we will go over how to use Salesforce to create the due date formula field.

Salesforce Due Date Formula Field

In Salesforce, to make sure our tasks and projects are completed on time, we use a Due Date. To achieve this, we can create a Due Date formula field that automatically calculates the due date based on the requirement.

To create the due date formula, Salesforce provides various built-in functions that help us set it based on specific criteria. Let’s examine some common uses of the due date formula in Salesforce.

Due Date based on the specified number of days:

In a simple case, we calculate the due date based on the created, started, and payment dates, as well as a specified number of days.

Here is the formula:

DATEVALUE(Created/Started/PaymentDate) + No.of.days
  • This formula is used to calculate the due date based on the specific number of days to add.
  • Here, we use the DATEVALUE function to convert the Created/Started/PaymentDate if given in date and time data type to a date value.
  • Then, the number of days is the API Name that stores the number of days to add to the Created/Started/PaymentDate.

Due Date based on specific days of the month:

In this case, we calculate the due date based on specific days of the month.

Here is the formula:

IF(DAY(Created/Started/PaymentDate) <= 18, 
   DATE(YEAR(Created/Started/PaymentDate), MONTH(Created/Started/PaymentDate), 18), 
   DATE(YEAR(Created/Started/PaymentDate), MONTH(Created/Started/PaymentDate) + 1, 1)) 
+ No.of.Days
  • Here, we use the IF function that checks the day of the month when the record was created, started, or the payment date is less than or equal to 18.
  • If it is, the formula uses the DATE function to create a new date using YEAR, MONTH, and day 18th of that month.
  • If the Created/Started/PaymentDate is after the 18th, the formula uses the DATE function to create a new date by setting the year, month, and day to the next month’s 1st.
  • Then, to calculate the due date, add the number of days.

We can use any of the above-defined formulas by creating a custom formula field in Salesforce. Let’s move to the next section and learn to create a formula field on the object where we want to set the due date.

With this, we now know about the Salesforce Due Date Formula. Next, we will proceed to learn how to set the due date in Salesforce Lightning.

Formula to Calculate Due Date in Salesforce Lightning

Here are the steps to define the formula to calculate the due date in Salesforce Lightning.

  1. Click the Setup icon in the top right corner of the page to access Salesforce Setup.
    • Click Object Manager from the menu’s left side.
Salesforce Due Date Formula
  1. Look for the item to which we want to set the due date. In this example, I choose the Product object from the list of objects.
Salesforce Due Date Formula Example
  1. Choose Fields & Relationships. Next, select New.
Salesforce Due Date Formula Example
  1. Select “Formula” as the field type. Click Next to proceed.
Salesforce Lightning Due Date Formula Example
  1. After entering a Field Label for the formula, the Field Name will be filled in automatically. Here, I enter the Field Label as the Payment Due Date.
    • Select Date as the Formula Return Type. After that, click Next.
Formula to calculate Due Date in Salesforce Lightning
  1. Enter the formula that calculates the due date in the Advanced Formula editor. The formula is given below:
Payment_Date__c +5 
  • In this formula, we add 5 days to a date value stored in a field called “Payment_Date__c”. It helps us to calculate the due date by adding a number of days to an existing payment date.
  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 alternatives.
    • Then, select Next.
Salesforce Due Date Formula
  1. Select the appropriate Field Level Security, and to make it visible to everyone, we select the Visible checkbox.
    • Select Next.
Formula to calculate Due Date using Salesforce Lightning
  1. Select the Page Layout Name for which the formula field is to be added. Click Save to save the formula field.
Formula to calculate Due Date using Salesforce Lightning Example
  1. We can use the formula field once it has been created. Let’s look at an example:
    • Create a product with a payment date field by opening the Products item and saving it.
    • After that, click on the Details section, and the Payment Due Date field will appear.
Salesforce Lightning Formula to calculate Due Date

As a result, we now know how to use Salesforce Lightning’s advanced formula to set the due date.

Conclusion

With this, we have learned the Salesforce Due Date Formula. Moreover, we have learned the simple procedure for setting the due date in Salesforce Lightning.

You may also like the following Salesforce tutorials:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.