Extract date (yyyy/mm/dd) from a timestamp in PostgreSQL

前端 未结 7 1491
南旧
南旧 2020-11-28 17:55

I want to extract just the date part from a timestamp in PostgreSQL.

I need it to be a postgresql DATE type so I can insert it into another table that e

7条回答
  •  伪装坚强ぢ
    2020-11-28 18:33

    Use the date function:

    select date(timestamp_field) from table
    

    From a character field representation to a date you can use:

    select date(substring('2011/05/26 09:00:00' from 1 for 10));
    

    Test code:

    create table test_table (timestamp_field timestamp);
    insert into test_table (timestamp_field) values(current_timestamp);
    select timestamp_field, date(timestamp_field) from test_table;
    

    Test result:

    pgAdmin result

    pgAdmin result wide

提交回复
热议问题