Forum Moderators: coopster
I have problem with my viewing my sql date format
Use this when I save the date to my mySQL table:
$cdate=date("m/d/y");
$dateend = date("m/d/Y", strtotime("+3 days"));mysql_query("INSERT INTO Mtable
VALUES ('$cdate',
'$dateend')") or die(mysql_error());
The above code works, but when I retrieve it and try to view the result using the following code:
echo $myrow[dateend];
echo $myrow[datepost];
I got this results :
for dateend 2009-04-20
and for datepost 2009-01-04
I tried to use this code:
echo date ("F j, Y",$myrow[dateend]);
echo date("F j, Y",$myrow[datepost]);
but I get the following result for both code:
December 31, 1969
Need your help, thank you in advance
Something like this:
$query = ("SELECT DATE_FORMAT(datepost, '%F %j, %Y') as display_time FROM tablename LIMIT 1") or die(mysql_error());
$row = mysql_fetch_object($query);
echo $row->display_time;
You may not need mysql_fetch_object or the limit clause, they are just here for examples.
You need to use DATE_FORMAT because the DATE field by default displays in the US format. Alternatively you can just store the value of F j Y in a varchar field.