sql >> Base de Datos >  >> RDS >> PostgreSQL

PostgreSQL:¿cómo convertir de la época de Unix a la fecha?

Usas to_timestamp función y luego convertir la marca de tiempo a date

 select to_timestamp(epoch_column)::date;

Más detalles:

/* Current time */
 select now();  -- returns timestamp

/* Epoch from current time;
   Epoch is number of seconds since 1970-01-01 00:00:00+00 */
 select extract(epoch from now()); 

/* Get back time from epoch */
 -- Option 1 - use to_timestamp function
 select to_timestamp( extract(epoch from now()));
 -- Option 2 - add seconds to 'epoch'
 select timestamp with time zone 'epoch' 
         + extract(epoch from now()) * interval '1 second';

/* Cast timestamp to date */
 -- Based on Option 1
 select to_timestamp(extract(epoch from now()))::date;
 -- Based on Option 2
 select (timestamp with time zone 'epoch' 
          + extract(epoch from now()) * interval '1 second')::date; 

En su caso:

 select to_timestamp(epoch_ms / 1000)::date;

Documentos de PostgreSQL