What is YEAR() in SQL?

The YEAR() function returns the year from a date sent as a parameter.

Figure 1 shows a visual representation of the YEAR() function.

Figure 1: Visual representation of YEAR() function

Syntax

YEAR(date)

Parameter

The YEAR() function takes the date as a parameter.

The date must be in the format YYYY-MM-DD, or else this function returns NULL.

Return value

The YEAR() function returns the year from a date sent as a parameter.

It returns NULL if the date is invalid.

Code

The following example shows how we can isolate the year from the admission dates of students using the YEAR() function.

Students

Student ID

Student Name

Student Admission Date

1

David

2000-07-14

2

Luiss

2002-08-15

3

Harvey

2005-04-19

4

Lucy

2010-01-27

5

Andrew

2011-10-03

SELECT *, YEAR(studentAdmissionDate) as YEAR
from Students;
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources