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

### Table of Contents

- YEAR function syntax
- YEAR function arguments
- YEAR function example
- 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. YEAR function syntax

YEAR(*serial_number*)

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

## 3. YEAR function example

Formula in cell C3:

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

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

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

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

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

## 6. YEAR function not working?

### 6.1 YEAR function returns #NAME! error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

## 16. Get Excel file

### 'YEAR' function examples

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 […]

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