Home >Database >Mysql Tutorial >How to Extract YYYY/MM/DD Dates from PostgreSQL Timestamps?
Extracting Date (YYYY/MM/DD) from PostgreSQL Timestamps
Need to isolate the date component from timestamps in PostgreSQL? Here's how:
Using the ::date Suffix
Simply append ::date to your timestamp to get a DATE type value. For instance, with the timestamp '2010-01-01 12:00:00'::timestamp, the result is:
'2010-01-01 12:00:00'::timestamp::date; >> 2010-01-01
Employing the date_trunc Function
Unlike the ::date suffix which preserves the time zone, date_trunc returns a date value in the same data type as the timestamp, retaining the time zone if necessary. Consider the example:
select date_trunc('day', now()); >> 2015-12-15 00:00:00+02
The above is the detailed content of How to Extract YYYY/MM/DD Dates from PostgreSQL Timestamps?. For more information, please follow other related articles on the PHP Chinese website!