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

(2007-06-26)

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

Thank you very much,
dg

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
http://www.plus2net.com/php_tutorial/php_date_format.php

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;
<?php
$oldDate="2007-06-26";
$newDate=date("m-d-Y",strtotime($oldDate));
echo $newDate;
?>

outputs: 06-26-2007
For more info, see the php date manual:
http://us3.php.net/date

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.