Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Extract Year from DATE in POSTGRESQL

Date is in 'YYYY-MM-DD' text format, now I need to extract the year part which must be in numeric. I need this conversion to be done in single step, Since I need to use in other application where i cannot create new variable.

TO_DATE(t0.AESTDTC,'YYYY-MM-DD'),'YYYY-MM-DD' with this i was able to convert to date but Now i need to Extract the year from this date in single step? can any one help me?

like image 605
Karthi Avatar asked Mar 24 '16 15:03

Karthi


People also ask

What data type is year in PostgreSQL?

Postgres uses the DATE data type for storing different dates in YYYY-MM-DD format. It uses 4 bytes for storing a date value in a column. You can design a Postgres table with a DATE column and use the keyword DEFAULT CURRENT_DATE to use the current system date as the default value in this column.

What is epoch in PostgreSQL?

Posted on 23rd August 2022. YES, you can convert EPOCH to Timestamp by merely switching to the present Timestamp in PostgreSQL DBMS. EPOCH time is nothing but the number of seconds from 00:00:00 UTC on 1 January 1970. Till date, without adding the extra leap year days, this is considered.


1 Answers

Try

select date_part('year', your_column) from your_table; 

or

select extract(year from your_column) from your_table; 
like image 179
flaviodesousa Avatar answered Nov 13 '22 18:11

flaviodesousa