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

### Article with the 'YEAR' Function

The following article has a formula that contains the YEAR function.

Calculate date given weekday and week number

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'

The YEAR function function is one of many functions in the 'Date and Time' category.

The DATE function returns a number that acts as a date in the Excel environment. The image above shows you […]

How to use the DATEDIF function

The DATEDIF function returns the number of days, months, or years between two dates. The DATEDIF function exists in order to […]

How to use the DATEVALUE function

The DATEVALUE function returns an Excel date value (serial number) based on a date stored as text. Excel Function Syntax […]

The DAY function extracts the day as a number from an Excel date. Formula in cell C3: =DAY(B3) Excel Function […]

The DATE function calculates the number of days between two dates. Formula in cell D3: =DAYS(B3,C3) Excel Function Syntax DAYS(end_date, […]

The EDATE function returns a date determined by a start date and a number representing how many months. Use EDATE […]

How to use the EOMONTH function

The EOMONTH function returns an Excel date for the last day of a given month using a number and a start […]

Returns an integer representing the hour of an Excel time value. The returning number is ranging from 0 (12:00 A.M.) […]

How to use the MINUTE function

Returns a whole number representing the minute based on an Excel time value. The returned number is ranging from 0 […]

Extracts the month as a number from an Excel date. Formula in cell C3: =MONTH(B3) Excel Function Syntax MONTH(serial_number) Arguments […]

How to use the NETWORKDAYS function

The NETWORKDAYS function returns the number of working days between two dates, excluding weekends. It also allows you to ignore […]

How to use the NETWORKDAYS.INTL function

The NETWORKDAYS.INTL function calculate the number of working days between two dates, excluding weekends. It also allows you to ignore […]

The NOW function returns the current date and time. Formula in cell B3: =NOW() Excel Function Syntax NOW() Arguments The […]

How to use the SECOND function

Returns an integer representing the second based on an Excel time value. The returning number is ranging from 0 to […]

The TIME function returns a decimal value between 0 (zero) representing 12:00:00 AM and 0.99988426 representing 11:59:59 P.M. Formula in cell […]

How to use the TIMEVALUE function

The TIMEVALUE function returns a decimal number based on a text string. Excel uses decimal numbers between 0 and 0.99988426 […]

The TODAY function returns the Excel date (serial number) of the current date. Warning! This function is volatile meaning it […]

How to use the WEEKDAY function

Converts a date to a weekday number from 1 to 7. Formula in cell D3: =WEEKDAY(B3) Excel Function Syntax WEEKDAY(serial_number,[return_type]) […]

How to use the WEEKNUM function

The WEEKNUM function calculates a given date's week number based on a return_type parameter that determines which day the week […]

How to use the WORKDAY function

The WORKDAY function returns a date based on a start date and a given number of working days (nonweekend and […]

The YEAR function converts a date to a number representing the year in the date. The number is between 1900 […]

How to use the YEARFRAC function

The YEARFRAC function returns the fraction of the year based on the number of whole days between a start date […]

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