Data Validation is a feature in Microsoft Excel which restricts the values or type of data that users enter into a cell. It automatically checks whether the value entered is allowed based on the specified criteria. This step by step tutorial will assist all levels of Excel users in allowing only dates in a specific year.
Figure 1. Final result: Data validation date in specific year
Working formula: =YEAR(C3)=2019
Syntax of YEAR Function
YEAR function returns an integer corresponding to the year portion of a date; the year returned is between 1900 and 9999
=YEAR(serial_number)
- Serial_number – a date whose year we want to find; can be a date enclosed in quotation marks or a cell reference
- The date must be between January 1, 1900 and December 31, 9999
Setting up Our Data
Our table consists of two columns: Order No. (column B) and Delivery Date (column C). We want to restrict the delivery dates entered in column C and allow only dates in year 2019. We can do this by applying Data Validation.
Figure 2. Sample data: Data validation date in specific year
Allow only dates in year 2019
We want to restrict the dates that we input in column C and allow only dates in the year 2019. We can do this with Data Validation by following these steps:
Step 1. Select the cells whose values we want to restrict. In this case, select cells C3:C7
Step 2. Click the Data tab, then the Data Validation menu and select Data Validation
Figure 3. Selecting Data Validation
The Data Validation dialog box will pop up.
Figure 4. Data Validation preview
Step 3. Click the Allow: drop-down button and select Custom as Validation criteria
Step 4. Enter the following in the Formula bar: =YEAR(C3)=2019
Figure 5. Creating a data validation rule
The YEAR function returns the year portion of the date in column C. If the year is 2019, our formula returns TRUE.
For every date entered in column C that is specifically in the year 2019, the validation criteria returns TRUE, Data Validation passes and the value is allowed. Otherwise, Data Validation fails and the value is restricted.
Step 5. Click OK
We have now restricted the values in C3:C7 to allow only the dates in the year 2019. Let us try and enter “1/15/2019” into cell C3.
Figure 6. Date in year 2019 allowed by Data Validation
The date “1/15/2019” is allowed because it is in the year 2019, satisfying the Data Validation rule. Now let’s input “1/20/2018” into cell C4.
Figure 7. Date in year 2018 restricted by Data Validation
The date “1/20/2018” is not in the year 2019, hence Data Validation has restricted the input of “1/20/2018” into cell C4. For restricted values, Excel shows a default warning message that says:
“The value you entered is not valid. A user has restricted values that can be entered into this cell.”
We are then presented with three options: Retry, Cancel or seek Help.
Data Validation is very accurate in allowing only the values as specified in the formula or validation criteria. See below table that is filled up with dates in column C in the year 2019, and allowed by Data Validation.
Figure 8. Output: Data Validation date in specific year “2019”
Note
We can also use Data Validation to allow only dates that fall specifically in the current year. In the validation rule, we can use the following formula:
=YEAR(C3)=YEAR(TODAY())
This way, the cells in column C will pass validation only if the date entered is in the current year.
Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.
Leave a Comment