Salesforce Formula If Date is Less Than Today

In this Salesforce tutorial, I will explain how to create a formula if the date is less than today in Salesforce.

Salesforce Formula If Date is Less Than Today

You can create a formula in Salesforce to check if the date is less than today in Salesforce. To do so, use the comparison operators Less Than (<) or Less Than or Equal to (<=) to compare the value of the set date with the today field.

Below is the formula to check if the date is less than today.

DateField < TODAY()
                #OR
DateField <= TODAY()

Formula for Date Less Than Today in Salesforce

Below are the steps to define a formula date less than today’s date in Salesforce.

1. Move to the Setup, click on the Object Manager, search for the Object whose record date you want to check, and click on it. For example, choose the Contract object.

Salesforce Formula for Date Less Than Today Example

2. Choose the Fields & Relationships option and then click on the New option.

Formula for Date Less Than Today in Salesforce Lightning

3. After that, click on the Formula as the field type and then click Next to proceed.

Formula for Date Less Than Today in Salesforce Lightning Example

4. Enter the Field Label for the formula; the Field Name will be filled in automatically. Here, I enter Field Label as Validation. Then select Text as the Formula Return Type. After that, click Next.

Date Less Than Today in Salesforce Lightning

5. Enter the date less than today’s date formula in the Advance Formula editor. Here is the formula:

IF( EndDate  < TODAY(), "Contract time period is over. Please renew it.", "Contract is valid for " & TEXT( EndDate - TODAY()) & " days.")
  • The IF function determines whether the contract end date, called EndDate, is less than the current day, called TODAY. If so, the text Contract time period is over. Please renew it is returned.
  • Otherwise, it returns the text Contract is valid for X days, where X represents the number of days remaining until the contract end date.
  • The number of days left is converted into text using the TEXT function so that it can be included with the text using & the concatenation operator.
See also  Salesforce Due Date Formula

Then, verify that the formula is valid and click Check Syntax. Optionally fill in the Description and Help Text as alternatives. After that, click on the Next.

Date Less Than Today in Salesforce Lightning Example

6. Select the Profiles to which you want to give the edit access of the field. After that, click on the Next button.

Advance Formula for Date Less Than Today in Salesforce Lightning

7. Select the Page Layout where you want to add the field. If you don’t select the page layout, the field will not added. Click Save to save the formula field.

Advance Formula for Date Less Than Today in Salesforce Lightning Example

You can check the result of the if date is less than the formula result. For this, click on the Details section, and you will get the Validation field for the Contract.

Salesforce Lightning Formula for Date Less Than Today Example
When the End Date is more than today’s date it prints “Contract time period is over. Please renew it”.
Salesforce Lightning Formula for Date Less Than Today
When the End Date is less than today’s date it prints “Contract is valid for X days”.

Conclusion

I hope you have understood how to create the formula if the date is less than in Salesforce.

You may also like to read: