In order to Get YEAR from Timestamp in postgresql we use Extract Keyword. Within the Extract keyword we have to mention YEAR as we are getting year from timestamp
Let’s see how to
- Extract year from Timestamp in Postgresql
- Create the column which extracts year from timestamp column
With an example for both
Extract YEAR from Timestamp in Postgresql:
Within the Extract keyword we have to mention YEAR as we are getting year from timestamp
SELECT EXTRACT (YEAR FROM TIMESTAMP '2011-11-22 13:30:15')
So the resultant year will be
EXTRACT YEAR from Timestamp in column of Postgresql table:
We use table student_detail
Create the column which extracts YEAR from timestamp column in Postgresql:
We have created a column and stored YEAR from Birthdaytime column
SELECT *,EXTRACT (YEAR FROM Birthdaytime) AS Year FROM Student_detail
So the resultant table will be