0

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

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by buddylee17
0

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

0

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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.