pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedConverting RFC 2822 "timestamp" to timestampz
3+ messages / 2 participants
[nested] [flat]
* Converting RFC 2822 "timestamp" to timestampz
@ 2005-10-12 19:14 Milen A. Radev <mradev@gmail.com>
2005-10-12 19:31 ` Re: Converting RFC 2822 "timestamp" to timestampz Steve Crawford <scrawford@pinpointresearch.com>
0 siblings, 1 reply; 3+ messages in thread
From: Milen A. Radev @ 2005-10-12 19:14 UTC (permalink / raw)
To: pgsql-php
I have a RFC2822 timestamp (example: Thu, 21 Dec 2000 16:01:07 +0200).
I need to convert it to "timestampz" but I stumbled on the timezone
conversion. The code follows:
$timestamp = date( 'Y-m-d H:i:s O', strtotime( $rfc2822_timestamp) );
Unfortunately the supported formats for timezone in PHP and PostgreSQL
differs. Pgsql requires zone name or offset in the format "H:M"
(http://www.postgresql.org/docs/8.0/static/datatype-datetime.html#DATATYPE-TIMEZONE-TABLE).
The "date" function in PHP (versions up to 5.0) supports the following
two formats: "Difference to Greenwich time (GMT) in hours. Example:
+0200" and "Timezone offset in seconds: -43200 through 43200".
Of course I could play a little bit with last number (converting it to
"hours:minutes") but it seems unnatural. Am I missing something?
--
Milen A. Radev
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Converting RFC 2822 "timestamp" to timestampz
2005-10-12 19:14 Converting RFC 2822 "timestamp" to timestampz Milen A. Radev <mradev@gmail.com>
@ 2005-10-12 19:31 ` Steve Crawford <scrawford@pinpointresearch.com>
2005-10-12 20:01 ` Re: Converting RFC 2822 "timestamp" to timestampz Milen A. Radev <mradev@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Steve Crawford @ 2005-10-12 19:31 UTC (permalink / raw)
To: pgsql-php; milen@radev.net
On Wednesday 12 October 2005 12:14, Milen A. Radev wrote:
> I have a RFC2822 timestamp (example: Thu, 21 Dec 2000 16:01:07
> +0200). I need to convert it to "timestampz" but I stumbled on the
> timezone conversion....
The following works for me:
# select 'Thu, 21 Dec 2000 16:01:07 +0200'::timestamptz;
timestamptz
------------------------
2000-12-21 06:01:07-08
Cheers,
Steve
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Converting RFC 2822 "timestamp" to timestampz
2005-10-12 19:14 Converting RFC 2822 "timestamp" to timestampz Milen A. Radev <mradev@gmail.com>
2005-10-12 19:31 ` Re: Converting RFC 2822 "timestamp" to timestampz Steve Crawford <scrawford@pinpointresearch.com>
@ 2005-10-12 20:01 ` Milen A. Radev <mradev@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Milen A. Radev @ 2005-10-12 20:01 UTC (permalink / raw)
To: Steve Crawford <scrawford@pinpointresearch.com>; +Cc: pgsql-php
On 12/10/05, Steve Crawford <scrawford@pinpointresearch.com> wrote:
> On Wednesday 12 October 2005 12:14, Milen A. Radev wrote:
> > I have a RFC2822 timestamp (example: Thu, 21 Dec 2000 16:01:07
> > +0200). I need to convert it to "timestampz" but I stumbled on the
> > timezone conversion....
>
> The following works for me:
>
> # select 'Thu, 21 Dec 2000 16:01:07 +0200'::timestamptz;
>
> timestamptz
> ------------------------
> 2000-12-21 06:01:07-08
You are so right! I was confused by another bug in my query to believe
that the RFC2822 format is unacceptable.
--
Milen A. Radev
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-10-12 20:01 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-12 19:14 Converting RFC 2822 "timestamp" to timestampz Milen A. Radev <mradev@gmail.com>
2005-10-12 19:31 ` Steve Crawford <scrawford@pinpointresearch.com>
2005-10-12 20:01 ` Milen A. Radev <mradev@gmail.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