Re: how to add seconds to a TimestampTz - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: how to add seconds to a TimestampTz
Date
Msg-id 20070320132938.GR24234@alvh.no-ip.org
Whole thread Raw
In response to how to add seconds to a TimestampTz  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
Alvaro Herrera wrote:
> Is there a better way than going to time_t and back?  I am currently
> using this:
> 
>     db->next_worker =
>         time_t_to_timestamptz(timestamptz_to_time_t(current_time) +
>                       autovacuum_naptime);
> 
> (db->next_worker is a TimestampTz, as is current_time.
> autovacuum_naptime is integer for a number of seconds)

For the archives, I just discovered on timestamp.h this macro to help:
avdb->ad_next_worker =    TimestampTzPlusMilliseconds(now, naptime_secs * 1000);

This is a lot simpler and faster ...

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Buildfarm feature request: some way to track/classify failures
Next
From: Andrew Dunstan
Date:
Subject: Re: modifying the tbale function