how to get year from date in sql code example
Example 1: get current year sql
select year(getdate())
Example 2: sql getdate date only
-- MS SQL Server
SELECT CAST(getdate() AS date);
SELECT CAST(getdate() AS varchar(10));
Example 3: extract year from date sql
SELECT extract(YEAR FROM sysdate) FROM dual; // number
SELECT to_char(sysdate, 'YYYY') FROM dual; // varchar
Example 4: print year of a date sql
SELECT EXTRACT(YEAR FROM CURRENT_DATE)
Example 5: sql get year from datetime field
SELECT YEAR(DateTimeField)
FROM MyTable