postgresqlHow can I extract the year from a date in PostgreSQL?
To extract the year from a date in PostgreSQL, you can use the EXTRACT function.
Example code
SELECT EXTRACT(YEAR FROM '2020-01-01'::DATE);
Output example
2020
The code above uses the EXTRACT function to extract the year from the date 2020-01-01. The YEAR keyword is used to specify the type of data to extract from the date.
Code explanation
SELECT: Used to query the databaseEXTRACT: Function used to extract data from a dateYEAR: Keyword used to specify the type of data to extract from the date2020-01-01: Date used in the example
Helpful links
More of Postgresql
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL XOR to compare two values?
- How can Zalando use PostgreSQL to improve its software development?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL UNION to combine the results of two queries?
- How do I use PostgreSQL and ZFS together?
- How do I parse XML data using PostgreSQL?
See more codes...