## How to use 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.

Formula in cell C3:

## Excel function syntax

YEAR(*serial_number*)

## Arguments

*serial_number* - The date you want to extract the year out of.

## Comments

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.

### Table of Contents

- Calculate year from date?
- How to extract the year from a text string
- YEAR 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. 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:

## 2. How to extract the year from a text string

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

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

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

## 3. YEAR function not working?

### 3.1 YEAR function returns #NAME! error

The YEAR function is misspelled in cell C3, Excel returns a #NAME! error.

### 3.2 YEAR function returns #VALUE! error

Cell B3 contains a text string that the YEAR function in cell C3 doesn't recognize as a date.

Formula in cell C3:

This formula extracts the year from the string.

Formula in cell C3:

### 3.3 YEAR function returns #NUM! error

Cell B3 contains a string of letters that the YEAR function doesn't recognize as an Excel date. It returns #NUM! error.

Formula in cell C3:

The following formula extracts the year from the string.

Formula in cell C3:

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

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

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

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

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

## 8. 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:

=YEAR(B3)&" Q"&INT((MONTH(B3)-1)/3)+1

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

## 9. Year as text

Formula in cell C3:

="The year is "&YEAR(B3)

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

## 10. 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:

=DATE(B3, MATCH(C3, {"January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December"}, 0), 1)

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

## 11. 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:

=DATE(2025, 1, ROW(A1)*7-6)

Formula in cell D3:

=TEXT(DATE(2025, 1, ROW(A1)*7-6), "m/d/yyyy")&" week:"&ISOWEEKNUM(DATE(2025, 1, ROW(A1)*7-6))

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

## 12. 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:

=TEXT(DATE(B3, 1,1), "ddddd")

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

## 13. Get Excel file

### 'YEAR' function examples

The following 25 articles contain the YEAR function.

The image above shows an Excel chart of the S&P 500 with buy and sell signals based on a 50 […]

Introduction In this post I am creating a spreadsheet that will calculate stock portfolio performance. To do this I am […]

This article demonstrates a formula that returns a date based on a week number and a weekday like Sun to […]

The formula in cell C3 calculates the last date for the given month and year in cell B3. =DATE(YEAR(B3), MONTH(B3)+1, […]

This article describes how to build a calendar showing all days in a chosen month with corresponding scheduled events. What's […]

This article demonstrates a macro that changes y-axis range programmatically, this can be useful if you are working with stock […]

Janib Soomro asks: In A column, there are dates in mmddyyy format and in B column, there are two variables […]

The formula in cell D18 counts unique distinct months in cell range B3:B16. Formula in D18: =SUMPRODUCT((FREQUENCY(DATE(YEAR($B$3:$B$16), MONTH($B$3:$B$16), 1), DATE(YEAR($B$3:$B$16), […]

The array formula in cell E3 counts unique distinct items for all dates within the same week. Example, week 2 […]

I will demonstrate three different techniques to build monthly date ranges in this article. Two of these techniques are easy because they […]

I will demonstrate three different methods to build quarterly date ranges in this article. The two first methods have a […]

This article demonstrates a formula that creates date ranges based on a given number of days and the end date […]

Excel has a great built-in tool for creating number series named Autofill. The tool is great, however, in some situations, […]

The image above demonstrates a formula in cell E3 that extracts duplicate items if they are on the same date. […]

Excel has a built-in feature that allows you to highlight dates if a given condition is met. Section 1 below […]

The image above demonstrates a conditional formatting formula that highlights duplicate items based on date. The first instance is not highlighted, […]

Color odd months Conditional formatting formula: =MOD(MONTH($B6),2) Explaining CF formula in cell B6 Step 1 - Calculate number of month The […]

If you study a stock chart you will discover that sometimes significant trend reversals happen when a stock chart […]

Did you know that you can use a pivot table to summarize portfolio holdings at any point in time? If you trade […]

The image above shows rows highlighted based on value in column C being the largest or smallest in that particular […]

This article demonstrates a formula that extracts unique distinct records/rows for a given month specified in cell C2, see the […]

This article shows a formula that performs a reverse lookup and returns the corresponding value based on the last matching […]

This article demonstrates how to build a calendar in Excel. The calendar is created as a Pivot Table which makes […]

The array formula in cell B15 extracts dates from B4:B12 if it is not a duplicate item in the same […]

What's on this page How to use this Excel Calendar How to add events How I built this calendar Worksheet […]

## Functions in this article

### Functions in 'Date and Time' category

The YEAR function function is one of many 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 signsUse 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 OscarYou can contact me through this contact form