Home > Archive > PHP with PostgreSQL > October 2005 > Converting RFC 2822 "timestamp" to timestampz









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Converting RFC 2822 "timestamp" to timestampz
Milen A. Radev

2005-10-27, 8:14 am

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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Steve Crawford

2005-10-27, 8:14 am

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

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Milen A. Radev

2005-10-27, 8:15 am

On 12/10/05, Steve Crawford < scrawford@pinpointre
search.com> wrote:
> On Wednesday 12 October 2005 12:14, Milen A. Radev wrote:
>
> 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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com