Answer: Extract a Value From a Date
Find a detailed explanation of how to extract the year from a date using an SQL query.
We'll cover the following...
We'll cover the following...
Solution
The solution is given below:
MySQL
/* 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
SELECTquery selects all the columns using*and the calculated column with the date/time functionYEARto find the year. We useASto set an alias for the column.Line 3: The
FROMclause specifies the table name asEmployeeDetails. ...