Skip to content
Advertisement

How to round timestamp to nearest day with postgresql

How can I round a timestamp to the nearest day in postgresql. I have tried using function date_trunc(‘day’, d_date::timestamp) but I get that is always staying in the same day.

Example 1:

Example 2: (This one works fine)

Advertisement

Answer

You could add 12 hours to the timestamp and then do the truncation that you’re doing already.

Something like…

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement