Re: any additional date_time functions?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: any additional date_time functions?
Date: 2006-06-18 09:54:50
Message-ID: 20060618095450.GA29167@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Jun 17, 2006 at 13:08:20 -0700,
Richard Broersma Jr <rabroersma(at)yahoo(dot)com> wrote:
> I am working with the date_trunc() function with great success especially in the group by clause
> for aggregates.
>
> However, it is limited to returning "WHOLE" time units. i.e. years, months, days, hours, minutes,
> seconds.
>
> Are there any functions similar to date_trunc that can return variable increments i.e.:
>
> 5, 10, or 15 minutes increments,
> 3, 4, 6 hour increments,
> 1, 2 weekly increments,
>
> I imagine that the returned values would have to either be the "floor" or "ceiling" of the actual
> time stamps.

You might be able to extract the time since the epoch and divide it by the
appropiate number of seconds (the length of your interval) and truncate
the result. This might have unexpected results for you when you span
daylight savings time changes.

Another option is to not use timestamp, but rather just store an integer that
represents some number of your intervals offset from an epoch.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Sim Zacks 2006-06-18 11:14:33 join on next row
Previous Message Ash Grove 2006-06-17 22:24:25 Re: concurrency problem