#17123 [Com]: mktime(), localtime(), strtotime(), etc. are broken for dates <1970 in Win32

From: Date: Tue, 10 Dec 2002 14:15:42 +0000
Subject: #17123 [Com]: mktime(), localtime(), strtotime(), etc. are broken for dates <1970 in Win32
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-27257@lists.php.net to get a copy of this message
ID: 17123 Comment by: f.vulto@re-base.com Reported By: jasonh@trurocollege.ac.uk Status: Won\'t fix Bug Type: Date/time related Operating System: WinNT5.0 PHP Version: 4.2.0 New Comment: PEAR offers a Date() and a Date_Calc() class which is capable of handling dates pre 1970 and post 2038. PEAR::Date is part of the standard PHP distribution. Example: require_once 'Date/Date.php'; $oDate =& new Date('1967-09-23 00:00:00'); print $oDate->format('%d/%B/%Y %H.%M.%S'); See also: http://pear.php.net http://docs.akbkhome.com/pearcvs/Date.html Previous Comments: ------------------------------------------------------------------------ [2002-11-24 14:47:12] asiop@yahoo.com Sadly, I had to rebuild date function to be compatible with mylocal.. here's the code, extensions are welcome: function mydate($format, $timestamp = null) { if ($timestamp == null) { return @date($format); } if ($timestamp > -1) { return @date($format, $timestamp); } $dateArr = $this->mylocaltime($timestamp, true); $search = array("s","i","H","d","m","Y","y", "z","I"); $replace = array(sprintf("%02d",$dateArr["tm_sec"]), sprintf("%02d",$dateArr["tm_min"]), sprintf("%02d",$dateArr["tm_hour"]), sprintf("%02d",$dateArr["tm_mday"]), sprintf("%02d",$dateArr["tm_mon"]+1), sprintf("%02d",$dateArr["tm_year"]+1900), sprintf("%02d",$dateArr["tm_year"] - (floor($dateArr["tm_year"] / 100) * 100)), $dateArr["tm_yday"], $dateArr["tm_isdst"]); return str_replace($search, $replace, $format); } // enjoy ------------------------------------------------------------------------ [2002-11-24 13:13:43] rasmus@php.net Just use Julian dates as supported by the calendar extension. ------------------------------------------------------------------------ [2002-11-24 13:11:42] asiop@yahoo.com The problem is that all of the PHP date functions are based on that miserable timestamp. At least if there were a consisent set of alternative functions that handle dates and bypass this problem it would be nice. The bottom line of having no official result for this is unbearable, there's no way to calculate the age diffrence of people who are older than 33.. This is quite basic and the lack of it makes this otherwise very strong language - very poor and unprofessional. too bad. ------------------------------------------------------------------------ [2002-11-04 04:53:54] Andreas@ap-stbr.de The problem still occurs with 4.2.3: mktime(0,0,0,09,23,1967) returns -1 instead of a valid timestamp. ------------------------------------------------------------------------ [2002-08-04 04:47:40] yohgaki@php.net Since the time stamp is started from 1970, I don't think it supposed to work in anyways. Or is there anything wrong is returned when too small/large date is supplied? It should fail, but it should not crash PHP for example. Please reopen if PHP behaves badly. BTW, there should be feature requests for more generic date functions so no need for feature request also. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/17123 -- Edit this bug report at http://bugs.php.net/?id=17123&edit=1

« previous php.bugs (#27257) next »