Skip site navigation (1) Skip section navigation (2)

Converting RFC 2822 "timestamp" to timestampz

From: "Milen A(dot) Radev" <mradev(at)gmail(dot)com>
To: pgsql-php(at)postgresql(dot)org
Subject: Converting RFC 2822 "timestamp" to timestampz
Date: 2005-10-12 19:14:32
Message-ID: 32c009ea0510121214x232f57c5w@mail.gmail.com (view raw or flat)
Thread:
Lists: 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

Responses

pgsql-php by date

Next:From: Steve CrawfordDate: 2005-10-12 19:31:39
Subject: Re: Converting RFC 2822 "timestamp" to timestampz
Previous:From: Volkan YAZICIDate: 2005-10-12 17:08:29
Subject: Re: Automatically opening pdf files stored in a bytea field

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group