skip to Main Content

How could I convert from Unix to "timestamp" until minutes?

For example, 1672718268 -> 2023-01-03 06:57
upd.: Format – not string

I tried to use function:

  • to_timestamp(timemodified)::date + date_trunc(‘hour’, timemodified) + date_part(‘minute’, timemodified)::int
  • to_timestamp(to_timestamp(timemodified)::timestamp,’YYYY-MM-DD HH24:MI’)
  • extract(epoch from timemodified) from table
  • date_trunc(‘minute’, to_timestamp(timemodified)::timestamp)

an example of desired output

2

Answers


  1. This should work:

    SELECT to_char(to_timestamp(1672718268), 'YYYY-MM-DD HH24:MI');
    

    The result will be a string, not a timestamp because a timestamp also has seconds.

    For just the date, cast your timestamp to a date:

    SELECT cast(to_timestamp(1672718268) as date);
    
    Login or Signup to reply.
  2. select to_char(date_trunc('minutes', to_timestamp(1672718268)), 'YYYY-MM-DD HH24:MI');
         to_char      
    ------------------
     2023-01-02 19:57
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search