ShoeLace1291 Posted May 25, 2007 Share Posted May 25, 2007 How do I select a DATETIME row from a MySQL table as a certain format? Since in MySQL, it's displayed as 2007-05-25 13:44:00 How would I get it to display as May 25, 2007, 1:44 P.M.? $news = mysql_query("SELECT newsID,posterID,headline,message,datetime as date(M j, o, g:i A) FROM news ORDER BY newsID DESC LIMIT 5") or die("Unable to connect to news database."); Link to comment https://forums.phpfreaks.com/topic/52978-solved-select-datetime-table-row-as-certain-format/ Share on other sites More sharing options...
Caesar Posted May 25, 2007 Share Posted May 25, 2007 Tip: Don't store formatted dates. Store them as time stamps...then it is extremely easy to compare them, order them, and format them for display purposes...in any format you like. Link to comment https://forums.phpfreaks.com/topic/52978-solved-select-datetime-table-row-as-certain-format/#findComment-261740 Share on other sites More sharing options...
Caesar Posted May 25, 2007 Share Posted May 25, 2007 Also... <?php $str = '2007-05-25 13:44:00'; $convertit = strtotime($str); $newtime = date("M d, Y", $convertit); echo $newtime; ?> Link to comment https://forums.phpfreaks.com/topic/52978-solved-select-datetime-table-row-as-certain-format/#findComment-261750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.