Archive for April, 2009

More Dates Madness

Wednesday, April 8th, 2009

Just did some cross browser testing – all works OK in firefox and safari and seamonkey and google chrome, but internet explorer croaks. The customer (not totally unreasonably) objected to dates being displayed as YYYY-MM-DD and wanted them displayed in the UK format of dd/month/yy. Unfortunately somewhere in the dates manipulation I used the Javascript Dates.parse function. this worked OK in Firefox and processed UK dates OK ie Date.parse(“1/Aug/2009”) gave the correct result of 1249081200000,
but in IE I got NaN.

Try it yourself in different browsers by putting UK style dates at

The Next Millennium Time Bomb

Friday, April 3rd, 2009

Just been working on a booking system for holiday lets and stumbled on the next millennium time bomb – I was using php mktime to add days to a date and discovered that if you add 1 day to Jan 1st 2037 the result is correct, but if you add 1 day to April 1st 2038 you get a date back in 1968 (a good year – but not the right answer!).

If you want to check it out yourself the PHP code is included below:

Function FindDate($sDate,$iDirection,$sTarget) {
// $sDate format YYYY-MM-DD from MySQL table
// $idirection to go forward or back in time 
// $sTarget day of week we want to find
do {
	$timestamp=mktime(0, 0, 0, $mm, $dd+$i, $yyyy);
	$w=date('D',$timestamp);  // gives Mon - Sun
	echo ($i." ".$sDate." ".$w);
	echo (date('Y-m-d',$timestamp)."\n");
    } while ($w!=$sTarget && abs($i<7));
$r= date('Y-m-d',$timestamp);
echo ($r."\n");
return $r;