|
Timestamps: mktime() on 32 bit systems |
|
Facts -
Php
|
|
Thursday, 10 June 2010 21:51 |
|
On my 32 bits centos 5.4 linux system the php function mktime() returns zero for dates from the year 2038. On a 64 bits centos 5.4 linux system mktime() works fine for dates from the year 2038.
I solved the problem on my 32 bit system by using the following customized version of mktime():
function myMkTime($year, $month, $day)
{
$tempYear = $year;
// these two corrections are not necessary on 64 bit systems
$yearCorrection = $tempYear >= 2038 ? 68:0;
$iDate = 1000*mktime(0,0,0, $month, $day, $tempYear -$yearCorrection);
if ($tempYear>=2038) {
$iDate += 1000*mktime(23,59,59, 12, 31, 2037);
}
// $iDate = 1000*mktime(0,0,0, $month, $day, $year); // use only this line on 64 bit systems
return $iDate;
}
|