YEAR
YEAR(date)
Section titled “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
Section titled “Example”SELECT YEAR('2021-07-01');Output
Section titled “Output”2021Explanation
Section titled “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)
Section titled “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
Section titled “Example”SELECT YEAR('2022-12-31') AS YearExtracted;Output
Section titled “Output”YearExtracted--------------2022Explanation
Section titled “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)
Section titled “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
Section titled “Example”SELECT YEAR(SYSDATE) FROM dual;Output
Section titled “Output”2023Explanation
Section titled “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.