I also fought with this when my site was using MySQL. I wrote two functions to convert the date either from MySQL to what my users want to see and the reverse. You may need to do the same. My users preference is month day year; if you/your users prefer something different these functions can be modified.
<?php
/*********************************************************************
File: DateFmtDspl2MyS.php
Purpose: This function converts an incoming dd Mon YYYY formated date
into the YYYY-MM-DD formated date for MySQL
History:
Mary Self, 6 July 2005, initial creation
I/O:
input parameter:
$Date: a display formatted date (dd Mon YYYY)
Calls:
none
Returns:
default MySQL formatted date (YYYY-MM-DD)
Tables Used/Modified:
none
Tables Referenced:
none
Comments:
********************************************************************/
function DateFmtDspl2MyS($Date)
{ // convert a date formatted for display into a MySQL date
$Mon = array (Jan => '01',
Feb => '02',
Mar => '03',
Apr => '04',
May => '05',
Jun => '06',
Jul => '07',
Aug => '08',
Sep => '09',
Oct => '10',
Nov => '11',
Dec => '12');
$Yr = substr($Date,-4, 4); // extract the year
$Mn = substr($Date, 3, 3); // extract the month
$Dy = substr($Date, 0, 2); // extract the day
$NewDate = $Yr.'-'.$Mon[$Mn].'-'.$Dy;
return $NewDate;
}
?>
<?php
/*********************************************************************
File: DateFmtMys2Dspl.php
Purpose: This function converts a MySQL data format to a
Day Month Year format for display.
History:
Mary Self, 6 July 2005, initial creation
I/O:
none
Calls:
?
Returns:
dd Mon YYYY formated date
Tables Used/Modified:
none
Tables Referenced:
none
Comments:
*********************************************************************/
function DateFmtMyS2Dspl($Date)
{ // convert a MySQL date into a date formatted for display
$Mon = array ("","Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$Yr = substr($Date, 0, 4); // extract the year
$Mn = substr($Date, 5, 2); // extract the month
$Dy = substr($Date, -2,2); // extract the day
$NewDate = $Dy.' '.$Mon[ltrim($Mn,'0')].' '.$Yr;
return $NewDate;
}
?>
I put each in a separate files that can be easily included and the function used.