PHP 4.0 Bug #6425 Updated: date() parsing functionality provides unexpected results.
| From: | Bug Database | Date: | Wed, 06 Sep 2000 21:16:51 +0000 |
| Subject: | PHP 4.0 Bug #6425 Updated: date() parsing functionality provides unexpected results. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-32460@lists.php.net to get a copy of this message | ||
ID: 6425
Updated by: sniper
Reported By: hirschf@home.com
Status: Open
Bug Type: Date/time related
Assigned To:
Comments:
reclassified..
Previous Comments:
[2000-09-06 17:15:54] sniper@php.net
User feedback:
---------------------------
I was actually contacted on this issue once, and sent a corrected reply as
follows. Keep in mind, this issue only occurs in _Windows_ versions of PHP
including PHP 4.0.1pl2 and 4.0.2. UNIX varients do not seem effected.:
I've written a specific script to show this issue:
--- cut ---
<?php
for ( $i = 1900; $i < 2050; $i++) {
$datep = "$i-01-01";
print "Trying: $datep ... ";
print date("F j, Y", strtotime($datep));
print "<BR>"; // For clean display sake only
}
?>
--- cut ---
I also tested this with dates in 12-31, and 1969 failed, so 1970-01-01 is
the lowest possible date:
--- cut ---
Trying: 1900-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
Trying: 1901-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
Trying: 1902-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
.
.
.
Trying: 1969-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
Trying: 1970-01-01 ... January 1, 1970
Trying: 1971-01-01 ... January 1, 1971
Trying: 1972-01-01 ... January 1, 1972
Trying: 1973-01-01 ... January 1, 1973
Trying: 1974-01-01
.
.
.
Trying: 2038-01-01 ... January 1, 2038
Trying: 2039-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
Trying: 2040-01-01 ...
Warning: unexpected error in date() in d:fhirschmysitetestdate.php on
line 6
... January 1, 1974
--- cut ---
It seems likely that the date() function uses internal calls within the O/S
somehow on Windows, as this would correlate to what Windows/MSDOS is
(in)capable of doing. However, it hardly seems to be a desirable side-effect
in a production quality programming language. Anyhow, let me know if there
is other documentation you need from me.
---------------------------------------
Editorial note: PLEASE answer next time using the
web-interface.. =)
--Jani
---------------------------------------------------------------------------
[2000-09-05 19:43:17] sniper@php.net
Your example code was buggy, below corrected one:
<?php
function parseDate($date,$format) {
$dateString = date($format , strtotime($date));
return $dateString;
}
$db_birth_date = "1969-09-13 00:00:00";
$birth_date = parseDate($db_birth_date,"F j, Y");
echo $birth_date;
?>
And this works just like it should (in Linux)..
Please try this and report back.
--Jani
---------------------------------------------------------------------------
[2000-08-29 19:58:01] hirschf@home.com
On Windows NT, using Apache tested in PHP 4.0.1PL2, 4.0.2 for Win NT using
Apache CGI PHP. The function date() with MySQL date format of
YYYY-MM-DD HH:MI:SS
yields an error when using dates with a value lower than 1970-01-01 00:00:00.
The following error is actually reported:
Warning: unexpected error in date() in Program.php line XXX
Below is a script which reproduces this error:
$db_birth_date = "1969-09-13 00:00:00";
$birth_date = $parseDate($db_birth_date',"F j, Y");
function parseDate($date,$format) {
$dateString = date($format , strtotime($date));
return $dateString;
}
Have not tested this issue on UNIX system yet.
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6425