|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
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. --JaniUser 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