Skip to content

DATE_PART

DATE_PART(text, timestamp) returns double precision

Section titled “DATE_PART(text, timestamp) returns double precision”
  • text: This is the first parameter which represents the part of the date/time value aimed to be extracted. This is a string input and includes options such as year, month, day, hour, minute, second, etc.
  • timestamp: This is the second parameter representing the timestamp from which the value will be extracted. The format is standard date/time format
SELECT DATE_PART('year', TIMESTAMP '2001-02-16 20:38:40');
2001

The DATE_PART function in PostgreSQL is used to extract a subfield (like year, month, day, etc.) from a date or time value. The example code provided fetches the ‘year’ element from the given timestamp.