ID: 9640
User Update by: [EMAIL PROTECTED]
Status: Open
Bug Type: Date/time related
Description: strtotime() cannot properly handle some ISO 8601-compliant strings

Another workaround for PostgreSQL (and the equivalent, if
one exists, of this on other databases will work as well):

Run your query using the date_part function so that
PostgreSQL returns the UNIX timestamp instead of an ISO
8601-style timestamp.  The query would look something like this:

SELECT date_part('epoch', timestamp) AS timestamp
FROM table

Then use can just us that those records returned directly
with PHP's date, strftime, gmdate, and etc. functions.

Previous Comments:
---------------------------------------------------------------------------

[2001-03-08 17:26:17] [EMAIL PROTECTED]
I've recently run into a problem.  This problem has been addressed in bug report 
#9007, but I thought I would try to provide more detailed information.

First, I'm pulling ISO 8601-compliant date strings from a PostgreSQL 7.0.3 database.

We'll illustrate this bug with a sample date: 1999-06-24 00:01:00-05.  Or June 24, 
1999, 12:01 AM CDT.

$timestamp = "1999-06-24 00:01:00-05";
$timestamp = strtotime($timestamp);
print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp));

Now, that output /should/ read "Thursday, June 24, 1999 00:01 CDT," instead it reads 
"Wednesday, June 23, 1999 19:06 CDT."  Even though PHP knows the timezone of the 
machine to be CST6CDT, it subtracts 5 hours from the time during conversion, 
regardless.

This is a Bad Thing(tm) because all programs should be ISO 8601-compliant.  Currently 
PHP4 is a lil' broken.  This should be fixed in the next release of PHP4, IMHO.  The 
bug probably actually resides in the code in ext/standard/parsedate.c that is borrowed 
from GNU Bison 1.28.  So maybe this bug should be reported to GNU's bug list as well.

In any case, here's a fix in the meantime...

If using PostgreSQL issue the command "SET DATESTYLE TO Postgres;" in all of your 
queries that return a timestamp.  That will cause the timestamp to be returned in this 
style: Thu Jun 24 00:01:00 1999 CDT.  This style will correctly parse, as we will 
illustrate with this example:

$timestamp = "Thu Jun 24 00:01:00 1999 CDT";
$timestamp = strtotime($timestamp);
print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp));

The output of this example is "Thursday, June 24, 1999 00:01 CDT," which is correct.

And that's all.

Derek P. Moore
[EMAIL PROTECTED]

---------------------------------------------------------------------------

[2001-03-08 17:16:14] [EMAIL PROTECTED]
I've recently run into a problem.  This problem has been addressed in bug report 
#9007, but I thought I would try to provide more detailed information.

First, I'm pulling ISO 8601-compliant date strings from a PostgreSQL 7.0.3.

We'll illustrate this bug with a sample date: 1999-06-24 00:01:00-05.  Or June 24, 
1999, 12:01 AM CDT.

$timestamp = "1999-06-24 00:01:00-05";
$timestamp = strtotime($timestamp);
print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp));

Now, that output /should/ read "Thursday, June 24, 1999 00:01 CDT," instead it reads 
"Wednesday, June 23, 1999 19:06 CDT."  Even though PHP knows the timezone of the 
machine to be CST6CDT, it subtracts 5 hours from the time during conversion, 
regardless.

This is a Bad Thing(tm) because all programs should be ISO 8601-compliant.  Currently 
PHP4 is a lil' broken.  This should be fixed in the next release of PHP4, IMHO.  The 
bug probably actually resides in the code in ext/standard/parsedate.c that is borrowed 
from GNU Bison 1.28.  So maybe this bug should be reported to GNU's bug list as well.

In any case, here's a fix in the meantime...

If using PostgreSQL issue the command "SET DATESTYLE TO Postgres;" in all of your 
queries that return a timestamp.  That will cause the timestamp to be returned in this 
style: Thu Jun 24 00:01:00 1999 CDT.  This style will correctly parse, as we will 
illustrate with this example:

$timestamp = "Thu Jun 24 00:01:00 1999 CDT";
$timestamp = strtotime($timestamp);
print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp));

The output of this example is "Thursday, June 24, 1999 00:01 CDT," which is correct.

And that's all.

Derek P. Moore
[EMAIL PROTECTED]

---------------------------------------------------------------------------


Full Bug description available at: http://bugs.php.net/?id=9640


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to