How to use the YEAR function
What is the YEAR function?
The YEAR function converts a date to a number representing the year in the date. The number is between 1900 and 9999. In other words, it extracts the year part from a given Excel date. It must be an Excel date for it to successfully get the year part.
Table of Contents
- Introduction
- Syntax
- Arguments
- Example
- Calculate year from date?
- How to extract the year from a text string
- Function not working
- Is date an Excel date?
- How to calculate years between dates?
- How to convert year to a date?
- Year and month
- Year and quarter
- Year as text
- Year and month to date?
- Year by week?
- The year begins on what weekday?
- Get Excel file
1. Introduction
What is an Excel date?
Dates are stored numerically but formatted to display in human-readable date/time formats, this enables Excel to do work with dates in calculations.
For example, dates are stored as sequential serial numbers with 1 being January 1, 1900 by default. The integer part (whole number) represents the date the decimal part represents the time.
This allows dates to easily be formatted to display in many date/time formats like mm/dd/yyyy, dd/mm/yyyy and so on and still be part of calculations as long as the date is stored numerically in a cell.
You can try this yourself, type 10000 in a cell, press CTRL + 1 and change the cell's formatting to date, press with left mouse button on OK. The cell now shows 5/18/1927.
Why are dates actually integers in Excel?
This allows for calculations like adding or subtracting days to a given date. It also allows for easy formatting meaning you can customize the look of a given date by formatting the cell to your needs.
2. Syntax
YEAR(serial_number)
3. Arguments
serial_number - The date you want to extract the year out of.
Excel uses whole numbers as dates. January, 1 , 1900 is 1 and January, 1, 2000 is 36526. There are 36525 days between those two dates.
4. Example
The image above shows different random dates in cell B3:B9, cells C3:C9 contains the YEAR function extracting the year from the corresponding date on the same row in column B. Cell D3:D9 displays the formula used in cells C3:C9.
Formula in cell C3:
5. How to calculate the year from a date?
The image above shows the YEAR function in cell C3, it calculates a 4-digit year number based on an Excel date (serial number).
Formula in cell C3:
6. How to extract the year from a text string
6.1 Date at the end of the text string
The image above demonstrates three different formulas that extract the year from a text string. Cell B3 is a text string with the four last characters being the year number.
Cell B4 has the year number between other characters both from the right and left. Cell C5 begins with the year numbers.
Formula in cell C3:
The RIGHT function extracts a given number of characters from a text string starting from right.
RIGHT(text, [num_chars])
text - B3
[num_chars] - 4
6.2 Date somewhere in the middle of the text string
Formula in cell C4:
The MID function returns a substring from a string based on the starting position and the number of characters you want to extract.
MID(text, start_num, num_chars)
text - B4
start_num - 5
num_chars - 4
The formula in cell C5 returns 1911.
6.3 Date at the beginning of the text string
Formula in cell C5:
The LEFT function extracts a given number of characters from a text string starting from the left.
LEFT(text, [num_chars])
text - B5
[num_chars] - 4
The formula in cell C5 returns 1986.
7. Function not working
The YEAR function returns
- #VALUE! error if you use a non-numeric input value.
- #NUM! error if the input value is a invalid number.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
How do I know the date is recognized as an Excel date?
Check the "Format Cells" dialog box and press with left mouse button on category "General". You should see a number and not a date.
How do I convert a date to an Excel date?
Try using the DATEVALUE function to convert a text date to an Excel date. Read this article if it is not working.
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The YEAR function requires numerical values between valid ranges which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
8. Is date an Excel date?
The image above demonstrates three different values, Excel dates are right-aligned by default, text and general values are left-aligned by default.
However, numbers are also right-aligned by default. This can be confusing.
To really make sure Excel recognizes an Excel date go to tab "Home" on the ribbon. Select the cell you want to examine, now check the "Number Format".
Make sure Excel sees the dates as valid dates, see the image below.
Why do you want dates to be Excel dates?
You can't sort dates as text and general values properly, also calculations can't be made to text dates.
9. How to calculate years between dates?
The image above demonstrates a formula that returns the number of years between two given dates.
Formula in cell C3:
You can't use the YEAR function to calculate this, YEAR(C3) - YEAR(B3) returns 3 (2019-2016 equals 3), however, the correct result is 2.
Read more about the DATEDIF function.
10. How to convert year number to a date?
The picture above demonstrates a formula that returns an Excel date based on a year number specified in cell B3.
Formula in cell D3:
The formula in cell B6 is identical as the formula in cell D3, however, the cell is formatted to only show the year number. Read the next section to find out how to format.
10.1 How to format Excel date to yyyy
- Select cell B6.
- Press CTRL + 1 to open the "Format Cells" dialog box, see the image above.
- Select "Custom"
- Type: yyyy
- Press with left mouse button "OK" button.
Cell B6 is an Excel date showing only the year as a number.
11. Format Excel date to year and month
The image above shows a worksheet with the same date 6/28/2025 in cells B3:B8, however, cells B4:B8 are formatted differently.
- Select cell containing an Excel date.
- Press CTRL + 1 to open the Format Cells dialog box, see the image above.
- Type: m/yyyy
- Press OK button to apply changes.
Cell B5 has this format: yyyy-m
Cell B6 has this format: yyyy-mm
Cell B7 has this format: mmm yyyy
Cell B8 has this format: mmmm yyyy
12. Format Excel date to year and quarter
The image above shows
I recommend the year first and then the quarter, it allows you to sort data.
Formula in cell C3:
Explaining formula in cell C3
Step 1 - Calculate number representing month
The MONTH function returns a number corresponding to a month in a year. January - 1, ... , December - 12.
MONTH(B3)
becomes
MONTH(B3)
and returns 6. June is the sixth month in a year.
Step 2 - Subtract with one
The minus sign lets you subtract numbers in an Excel formula.
MONTH(B3)-1
becomes
6-1 and returns 5.
Step 3 - Divide by 3
The forward slash character lets you divide numbers in an Excel formula.
(MONTH(B3)-1)/3
becomes
5/3 equals 1.666666666667.
Step 4 - Remove decimals
The INT function returns a whole number.
INT((MONTH(B3)-1)
becomes
INT(1.666666666667)
and returns 1.
Step 5 - Add 1
The plus sign lets you add numbers in an Excel formula.
INT((MONTH(B3)-1)/3)+1
becomes
1+1 equals 2.
Step 6 - Calculate year from an Excel date
YEAR(B3)
becomes
YEAR(45836)
and returns 2025.
Step 7 - Concatenate values
The ampersand character & lets you concatenate values in an Excel formula.
YEAR(B3)&" Q"&INT((MONTH(B3)-1)/3)+1
becomes
2025&" Q"&2
and returns 2025 Q2.
13. Year as text
Formula in cell C3:
9.1 Explaining formula in cell C3
Step 1 - Calculate year
YEAR(B3)
becomes
YEAR(45836)
and returns 2025.
Step 2 - Concatenate values
The ampersand character & lets you concatenate values in an Excel formula.
"The year is "&YEAR(B3)
becomes
"The year is "&2025
and returns "The year is 2025".
14. Year and month to date?
The formula demonstrated in cell B6 in the image above returns an Excel date based on the specified year and month in cells B3 and C3 respectively.
Formula in cell B6:
14.1 Explaining formula in cell C3
Step 1 - Calculate number corresponding to position
The MATCH function returns a number representing the position of a given month in a year. January - 1, ... , December - 12.
MATCH(C3, {"January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December"}, 0)
becomes
MATCH("February", {"January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December"}, 0)
and returns 2.
Step 2 - Calculate date
The DATE function creates an Excel date based on three arguments, year, month and day.
DATE(B3, MATCH(C3, {"January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December"}, 0), 1)
becomes
DATE(B3, 2, 1)
becomes
DATE(2024, 2, 1)
and returns 2/1/2024.
15. Year by week
The image above shows a formula in cell B3 that returns dates in a year by week. The formula in cell D3 also displays the week number.
Formula in cell B3:
Formula in cell D3:
15.1 Explaining formula in cell B3
Step 1 - Create number sequence 1 to n step 7
The ROW function calculates the row number of a cell reference.
ROW(reference)
ROW(A1)*7-6
becomes
1*7-6
becomes
7-6 equals 1.
Relative cell reference A1 changes automatically when you copy and paste the cell to cells below.
Step 2 - Create Excel date based on sequence
The DATE function creates an Excel date based on three arguments, year, month and day.
DATE(2025, 1, ROW(A1)*7-6)
becomes
DATE(2025, 1, 1)
and returns 1/1/2025.
16. The year begins on what weekday?
The image above shows a formula in cell D3 that returns the weekday of the first day in a given year, cell B3 specifies the year.
Formula in cell D3:
10.1 Explaining formula in cell B3
Step 1 - Create an Excel date of the first day in a given year
The DATE function creates an Excel date based on three arguments, year, month, and day.
DATE(B3, 1,1)
becomes
DATE(2021, 1,1)
and returns 44197 (1/1/2021).
Step 2 - Return weekday of the given date
The TEXT function converts a value to text in a specific number format.
TEXT(value, format_text)
TEXT(DATE(B3, 1,1), "ddddd")
becomes
TEXT(44197 , "ddddd")
and returns Friday.
17. Get Excel file
'YEAR' function examples
Table of Contents Automate net asset value (NAV) calculation on your stock portfolio Calculate your stock portfolio performance with Net […]
Table of Contents Count cells containing text from list Count entries based on date and time Count cells with text […]
This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]
Functions in 'Date and Time' category
The YEAR function function is one of 22 functions in the 'Date and Time' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form