php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6425 date() parsing functionality provides unexpected results.
Submitted: 2000-08-29 19:58 UTC Modified: 2000-12-07 11:35 UTC
From: hirschf at home dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.0.1pl2 OS: Windows NT 4.0 Workstation
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 44 = ?
Subscribe to this entry?

 
 [2000-08-29 19:58 UTC] hirschf at home dot 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-05 19:43 UTC] 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-09-06 17:15 UTC] 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:\fhirsch\mysite\testdate.php on
line 6

Trying: 1901-01-01 ...
Warning: unexpected error in date() in d:\fhirsch\mysite\testdate.php on
line 6

Trying: 1902-01-01 ...
Warning: unexpected error in date() in d:\fhirsch\mysite\testdate.php on
line 6
.
.
.
Trying: 1969-01-01 ...
Warning: unexpected error in date() in d:\fhirsch\mysite\testdate.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:\fhirsch\mysite\testdate.php on
line 6

Trying: 2040-01-01 ...
Warning: unexpected error in date() in d:\fhirsch\mysite\testdate.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-06 17:16 UTC] sniper@php.net
reclassified..
 [2000-11-02 15:12 UTC] dbeu@php.net
could you plese try the dev build from php4win.de and report wheter this is fixed?
 [2000-12-07 11:35 UTC] sniper@php.net
No feedback.
 [2002-04-01 01:03 UTC] cmackenz at optushom dot com dot au
This condition still exists in 4.1.2
I'm using Win2K Advanced Server with uptodate patchs (as of 1-April-2002). Tested with snipers test loop.

Trying: 1970-01-01 ... 
Warning: unexpected error in date() in c:\inetpub\wwwroot\entry_exam\testdate.php on line 5

Trying: 1971-01-01 ... January 1, 1971
Trying: 1972-01-01 ... January 1, 1972

.
.
.

Trying: 2038-01-01 ... January 1, 2038
Trying: 2039-01-01 ... 
Warning: unexpected error in date() in c:\inetpub\wwwroot\entry_exam\testdate.php on line 5
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 07:01:30 2024 UTC