YEAR
YEAR is a MySQL function that is used to extract the year from a date.
YEAR(date)
- date: Represents the date value from which the year part is to be extracted. This can be a date type or can be a string formatted in various date-compatible formats.
Example
Output
Explanation
The YEAR function in SQL extracts the year from a date. In the above example, 2021 is extracted from the date ‘2021-07-01’.
YEAR(date)
- date: The “date” parameter refers to a date expression from which the year is to be returned. This expression can be any of the various data types of the date and time data types category, such as DATETIME, DATE, SMALLDATETIME, etc. The function will extract the year part of the date and return it as an integer.
Example
Output
Explanation
The YEAR
function in SQL Server extracts the year from a given date. In this example, the function is used to extract the year value, 2022, from the date ‘2022-12-31’.
YEAR(date)
- date: This parameter is the input date from which the year is extracted. It should be a valid date format recognized by Oracle SQL. The YEAR function then returns the year part of this date as a four-digit format.
Example
Output
Explanation
The YEAR
function retrieves the year component from the current system date (SYSDATE
). The dual
table is a special one-row table present by default in all Oracle databases.