---
schema_version: "1"
id: 358057188d82c9e07941cb876283d005aed02caa287aee61b59ba6dbb66fdc21
title: Sample Date Validation Rules
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/fields_useful_validation_formulas_date.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.fields_useful_validation_formulas_date.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8d5c8711248388551e153f2143c9f4c94d3da52aeac1067f01de2b0ba5bb379b
description: 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.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Contact Manager</strong>, <strong>Group</strong>, <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, <strong>Developer</strong>, and <strong>Database.com</strong> Editions</td></tr></tbody></table>

For more information on any of the formula functions used in these examples, see [Formula Operators and Functions by Context](https://help.salesforce.com/s/articleView?id=platform.customize_functions.htm&release=264.0.0&type=5 "Use these operators and functions when building formulas. All functions are available everywhere that you can include a formula, such as formula fields, validation rules, approval processes, and workflow rules, unless otherwise specified.").

## Date Must Be a Weekday

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e102">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e105">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e102 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e105 ">Validates that the value of a custom date field is a weekday (not Saturday or
              Sunday).</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e102 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e105 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>CASE(MOD( My_Date__c - DATE(1900, 1, 7), 7),
0, 0,
6, 0,
1) = 0</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e102 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e105 ">Date must be a weekday.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e102 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e105 ">
              <samp class="parmname">My Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Date Must Be a Weekend Day

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:29.5%">
          <col style="width:70.5%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e187">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e190">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e187 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e190 ">Validates that the value of a custom date field is a Saturday or Sunday.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e187 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e190 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>CASE( MOD( My_Date__c - DATE(1900, 1, 7), 7),
0, 1,
6, 1,
0) = 0</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e187 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e190 ">Date must be a weekend day.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e187 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e190 ">
              <samp class="parmname">My Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Date Must Be in the Current Month

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:29.5%">
          <col style="width:70.5%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e272">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e275">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e272 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e275 ">Validates that a custom date field contains a date within the current month and
              year.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e272 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e275 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>OR (
YEAR( My_Date__c ) &lt;&gt; YEAR ( TODAY() ),
MONTH( My_Date__c ) &lt;&gt; MONTH ( TODAY() )
)</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e272 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e275 ">Date must be in the current month.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e272 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e275 ">
              <samp class="parmname">My Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e443">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e446">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e443 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e446 ">Validates whether a custom field called <samp class="parmname">My Date</samp> 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.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e443 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e446 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>DAY(My_Date__c) &lt;&gt;
IF(Month(My_Date__c)=12, 31, DAY(DATE(YEAR(My_Date__c),MONTH(My_Date__c)+1,1) - 1))
</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e443 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e446 ">Date must be the last day of the month.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e443 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e446 ">
              <samp class="parmname">My Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Date Must Be Within One Year of Today

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e531">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e534">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e531 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e534 ">Validates whether a custom field called <samp class="parmname">Follow-Up Date</samp> is within
              one year of today’s date. This example assumes a 365 day year. (It does not handle
              leap years.)</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e531 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e534 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>Followup_Date__c - TODAY() &gt; 365</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e531 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e534 ">Follow-Up Date must be within one year of today.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e531 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e534 ">
              <samp class="parmname">Follow-Up Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Day of Month Cannot Be Greater Than 15

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e619">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e622">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e619 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e622 ">Validates that a custom field called <samp class="parmname">Begin Date</samp> contains a date
              in the first 15 days of the specified month.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e619 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e622 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>DAY( Begin_Date__c ) &gt; 15</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e619 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e622 ">Begin Date cannot be after the 15th day of month.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e619 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e622 ">
              <samp class="parmname">Begin Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## End Date Cannot Be Before Begin Date

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e707">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e710">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e707 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e710 ">Validates that a custom field called <samp class="parmname">End Date</samp> does not come
              before another custom field called <samp class="parmname">Begin Date</samp>.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e707 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e710 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>Begin_Date__c &gt; End_Date__c</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e707 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e710 ">End Date cannot be before Begin Date.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e707 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e710 ">
              <samp class="parmname">Begin Date</samp>
            </td>

          </tr>
        </tbody>
      </table>

## Expiration Date Cannot Be Before Close Date

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:28.999999999999996%">
          <col style="width:71%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e798">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d66003e801">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e798 ">
              <strong>Description:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e801 ">Validates that a custom field called <samp class="parmname">Expiration Date</samp> does not
              come before <samp class="parmname">Close Date</samp>.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e798 ">
              <strong>Formula:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e801 ">
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>Expiration_Date__c &lt; CloseDate</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e798 ">
              <strong>Error Message:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e801 ">Expiration Date cannot be before Close Date.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e798 ">
              <strong>Error Location:</strong>
            </td>

            <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d66003e801 ">
              <samp class="parmname">Expiration Date</samp>
            </td>

          </tr>
        </tbody>
      </table>