Discard millisecond part from timestamp

后端 未结 3 1599
长情又很酷
长情又很酷 2020-12-01 01:22

How can I discard/round the millisecond part, better if the second part is also removed from a timestamp w/o timezone ?

3条回答
  •  误落风尘
    2020-12-01 01:48

    A cast to timestamp(0) or timestamptz(0) rounds to full seconds:

    SELECT now()::timestamp(0);
    

    Fractions are not stored in table columns of this type.

    date_trunc() truncates (leaves seconds unchanged) - which is often what you really want:

    SELECT date_trunc('second', now()::timestamp);
    

提交回复
热议问题