Thursday, August 9, 2007

strtotime in PHP doesn't work on dates before 1970

I learned a new lesson today! The PHP function strtotime does not work on dates prior to 1970.

Isn't that awesome!

Since we have super special date format from Oracle, I had to turn 23-NOV-54 into Nov 23, 1954.
I did it the long way.. don't ask me why?!

$pieces = explode("-", $propRDate);
//make the month mixed case
$propRMonth=$pieces[1];
$propRMonth=strtolower($propRMonth);
//don't know why, but it doesn't work to just to ucfirst, I have to strtolower first.
$propRMonth=ucfirst($propRMonth);
//now lets make the year's 4 digit!
if (($pieces[2] > 0) and ($pieces[2] < 20)) {
//then it's 19
$propRYear="20".$pieces[2];
} else {
$propRYear="19".$pieces[2];
}
$propRDate = $propRMonth." ".$pieces[0].", ".$propRYear;
Anyhow.. fun fun,

BFN

No comments: