How can I discard/round the millisecond
part, better if the second
part is also removed from a timestamp
w/o timezone
?
Use the setSeconds() method to remove the seconds and milliseconds from a date, e.g. date. setSeconds(0, 0) . The setSeconds method takes the seconds and milliseconds as parameters and sets the provided values on the date.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With