Answer: Extract a Value From a Date
Find a detailed explanation of how to extract the year from a date using an SQL query.
Solution
The solution is given below:
Press + to interact
/* The query to extract the year from a date */SELECT *, YEAR(DateOfJoining) AS YearOfJoiningFROM EmployeeDetails;
Explanation
The explanation of the code solution is given below:
Line 2: The
SELECT
query selects all the columns using*
and the calculated column with the date/time functionYEAR
to find the year. We useAS
to set an alias for the column.Line 3: The
FROM
clause specifies the table name asEmployeeDetails
. ...