Reputation: 149
please i need to get the How to round datetime to nearest hour from a field like below
2019-09-29 13:05:42
2019-09-29 13:06:16
2019-09-29 13:04:43
Upvotes: 1
Views: 1981
Reputation: 1269703
You can use date_trunc()
. If by "round" you mean truncate, then there is a built-in function:
date_trunc('hour', col)
If by "round" you really mean "round", then:
date_trunc('hour', col + interval '30 minute')
Upvotes: 2