From this post's answer, I have a datetime column where I do date_time::timestamp - INTERVAL '1 HOUR'
in the select statement.
What I want to do is that, I want to create a interval of a 15 minutes range (0, 15,30,45) So, the result should be like 2019-04-21 09:00:00 or 2019-04-21 09:15:00 and so on. The result should be change to the nearest time i.e. for 00:00 to 07:29 minute will be round down to 00:00 and 07:30 to 15:00 will be round up to 15:00.This apply to 15, 30 and 45 as well
So from 2019-04-21 09:52:29
should become 2019-04-21 09:45:00
and 2019-04-21 09:52:30
should become 2019-04-21 10:00:00
I have searched and found date_trunc
function but I don't know how to do base on what I specific.
Thank you!
Edit: I have look at the duplicated post and some answers. I found answer that used dateadd and datediff function but these functions cannot be use with postgresql.
select dateadd(minute, datediff(minute,0,GETDATE()) / 15 * 15, 0)
How can apply this to postgresql ?
Edit2: There are solutions that use a create function to round up and down but the above is quite better.