For some reason when i was creating my database I messed up in inserting data into mysql and now all dates are in

yyyy-mm-dd format so when the data are displayed it seems like


How do i change that to (mm-dd-yyyy) in php for users to understand it better.

Thank you very much,

Try this..

function formatDate($val)
list($date, $time) = explode(" ", $val);
list($year, $month, $day) = explode("-", $date);
list($hour, $minute, $second) = explode (":", $time);
return date("j-M-y  h:ia", mktime(($hour)+("2"), $minute, $second, $month, $day, $year));

$displayDate = formatDate($row['dateinmysql']);

echo $displayDate;

You can play around in line 7 with the date formats .. just as u wish..

for more formats make use of

store dates as unix time stamp, then you can have any display you like, or have user option to display the date in their chosen format from the php date functions, and date manipulation is a simple add/subtract
a small portion of the potential market uses mm dd yyy
a portion uses dd mm yy
a portion does use yy mm dd

havent tested the sql,

if (!mysql_query(sprintf("UPDATE table SET date = mktime(0,0,0, substr(date, 5, 2),substr(date, 2, 2),substr(date, 0, 4));  "))); { return false; }
 return true;

echo $newDate;

outputs: 06-26-2007
For more info, see the php date manual: