pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
any additional date_time functions?
3+ messages / 2 participants
[nested] [flat]

* any additional date_time functions?
@ 2006-06-17 20:08 Richard Broersma Jr <rabroersma@yahoo.com>
  2006-06-18 09:54 ` Re: any additional date_time functions? Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 3+ messages in thread

From: Richard Broersma Jr @ 2006-06-17 20:08 UTC (permalink / raw)
  To: pgsql-sql

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.

Regards,

Richard Broersma Jr.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: any additional date_time functions?
  2006-06-17 20:08 any additional date_time functions? Richard Broersma Jr <rabroersma@yahoo.com>
@ 2006-06-18 09:54 ` Bruno Wolff III <bruno@wolff.to>
  2006-06-18 15:28   ` Re: any additional date_time functions? Richard Broersma Jr <rabroersma@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Bruno Wolff III @ 2006-06-18 09:54 UTC (permalink / raw)
  To: Richard Broersma Jr <rabroersma@yahoo.com>; +Cc: pgsql-sql

On Sat, Jun 17, 2006 at 13:08:20 -0700,
  Richard Broersma Jr <rabroersma@yahoo.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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: any additional date_time functions?
  2006-06-17 20:08 any additional date_time functions? Richard Broersma Jr <rabroersma@yahoo.com>
  2006-06-18 09:54 ` Re: any additional date_time functions? Bruno Wolff III <bruno@wolff.to>
@ 2006-06-18 15:28   ` Richard Broersma Jr <rabroersma@yahoo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Broersma Jr @ 2006-06-18 15:28 UTC (permalink / raw)
  To: Bruno Wolff III <bruno@wolff.to>; +Cc: pgsql-sql

> > 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,
> 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.

Bruno,

Thanks for the suggestions.  I am going to "toy" around with them to see what I can get to work.

Thanks for the help.

Regards,

Richard Broersma Jr.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-06-18 15:28 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-17 20:08 any additional date_time functions? Richard Broersma Jr <rabroersma@yahoo.com>
2006-06-18 09:54 ` Bruno Wolff III <bruno@wolff.to>
2006-06-18 15:28   ` Richard Broersma Jr <rabroersma@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox