Re: [GENERAL] rounding a timestamp to nearest x seconds

2012-03-08 Thread Andy Colson
On 03/07/2012 08:11 PM, Daniele Varrazzo wrote: On Wed, Mar 7, 2012 at 3:09 PM, Andy Colsona...@squeakycode.net wrote: Took me a while to figure this out, thought I'd paste it here for others to use: create or replace function round_timestamp(timestamp, integer) returns timestamp as $$

[GENERAL] rounding a timestamp to nearest x seconds

2012-03-07 Thread Andy Colson
Took me a while to figure this out, thought I'd paste it here for others to use: create or replace function round_timestamp(timestamp, integer) returns timestamp as $$ select date_trunc('minute', $1) + cast(round(date_part('seconds', $1)/$2)*$2 || ' seconds' as interval); $$ language sql

Re: [GENERAL] rounding a timestamp to nearest x seconds

2012-03-07 Thread Daniele Varrazzo
On Wed, Mar 7, 2012 at 3:09 PM, Andy Colson a...@squeakycode.net wrote: Took me a while to figure this out, thought I'd paste it here for others to use: create or replace function round_timestamp(timestamp, integer) returns timestamp as $$        select date_trunc('minute', $1) +