search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

1 answers
Q&A Discard millisecond part from timestamp
Discard millisecond part from timestamp
P粉426906369 2025-11-29 15:43:46 Views 102

0

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

Your Answer
submit

1 answers
0

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.

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

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

date_trunc accepts various input for the the first argument "field". Use 'minute' to truncate to the minute (also discard seconds).

The data type of return values matches the input, i.e. timestamp / timestamptz / interval accordingly.

2025-12-03 20:44:56

submit

Popular tool

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use