Sample Date Validation Rules
Examples for date validation rules. For example, how to validate that the value of a custom field is a weekday, a Saturday or Sunday, that a custom date field contains a date within the current month and year, and more.
Required Editions
| Available in: both Salesforce Classic and Lightning Experience |
| Available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, Developer, and Database.com Editions |
For more information on any of the formula functions used in these examples, see Formula Operators and Functions by Context.
Date Must Be a Weekday
| Field | Value |
|---|---|
| Description: | Validates that the value of a custom date field is a weekday (not Saturday or Sunday). |
| Formula: | |
| Error Message: | Date must be a weekday. |
| Error Location: | My Date |
Date Must Be a Weekend Day
| Field | Value |
|---|---|
| Description: | Validates that the value of a custom date field is a Saturday or Sunday. |
| Formula: | |
| Error Message: | Date must be a weekend day. |
| Error Location: | My Date |
Date Must Be in the Current Month
| Field | Value |
|---|---|
| Description: | Validates that a custom date field contains a date within the current month and year. |
| Formula: | |
| Error Message: | Date must be in the current month. |
| Error Location: | My Date |
Date Must Be in the Current Year
| Field | Value |
|---|---|
| Description: | Validates that a custom date field contains a date within the current year. |
| Formula: |
YEAR( My_Date__c ) <> YEAR ( TODAY()
)
|
| Error Message: | Date must be in the current year. |
| Error Location: | My Date |
Date Must Be the Last Day of the Month
| Field | Value |
|---|---|
| Description: | Validates whether a custom field called My Date is the last day of the month. To do this, it determines the date of the first day of the next month and then subtracts 1 day. It includes special case logic for December. |
| Formula: | |
| Error Message: | Date must be the last day of the month. |
| Error Location: | My Date |
Date Must Be Within One Year of Today
| Field | Value |
|---|---|
| Description: | Validates whether a custom field called Follow-Up Date is within one year of today’s date. This example assumes a 365 day year. (It does not handle leap years.) |
| Formula: | |
| Error Message: | Follow-Up Date must be within one year of today. |
| Error Location: | Follow-Up Date |
Day of Month Cannot Be Greater Than 15
| Field | Value |
|---|---|
| Description: | Validates that a custom field called Begin Date contains a date in the first 15 days of the specified month. |
| Formula: | |
| Error Message: | Begin Date cannot be after the 15th day of month. |
| Error Location: | Begin Date |
End Date Cannot Be Before Begin Date
| Field | Value |
|---|---|
| Description: | Validates that a custom field called End Date does not come before another custom field called Begin Date. |
| Formula: | |
| Error Message: | End Date cannot be before Begin Date. |
| Error Location: | Begin Date |
Expiration Date Cannot Be Before Close Date
| Field | Value |
|---|---|
| Description: | Validates that a custom field called Expiration Date does not come before Close Date. |
| Formula: | |
| Error Message: | Expiration Date cannot be before Close Date. |
| Error Location: | Expiration Date |
Did this article solve your issue?
Let us know so we can improve!

