waverider303 Posted September 9, 2009 Share Posted September 9, 2009 I have a row that is a datetime datatype (2009-09-09 11:05:03) I want to retreuieve this information and have it be displayed as this: September 9th, 2009 This is what I have so far: $sql = "SELECT title, content, DATE_FORMAT(`date`,'%M %D, %Y') FROM news WHERE id=$id"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); $date = $row['date']; $title = $row['title']; $content = $row['content']; echo "<h3 class=\"cufonH3\">$title</h3>"; echo "<div class=\"dates\">".$date."</div>"; echo "<p>$content</p>"; Everything but the date displays Link to comment https://forums.phpfreaks.com/topic/173688-solved-sql-datetime-data-type-help/ Share on other sites More sharing options...
p2grace Posted September 9, 2009 Share Posted September 9, 2009 Change your query to this: $sql = "SELECT title, content, DATE_FORMAT(`date`,'%M %D, %Y') AS `date` FROM news WHERE id=$id"; Link to comment https://forums.phpfreaks.com/topic/173688-solved-sql-datetime-data-type-help/#findComment-915588 Share on other sites More sharing options...
waverider303 Posted September 9, 2009 Author Share Posted September 9, 2009 Worked like a charm! Link to comment https://forums.phpfreaks.com/topic/173688-solved-sql-datetime-data-type-help/#findComment-915700 Share on other sites More sharing options...
p2grace Posted September 9, 2009 Share Posted September 9, 2009 Glad to hear it Could you mark the topic as solved when you get a chance? Cheers, p2grace Link to comment https://forums.phpfreaks.com/topic/173688-solved-sql-datetime-data-type-help/#findComment-915702 Share on other sites More sharing options...
gerardcorr Posted January 8, 2010 Share Posted January 8, 2010 http://www.mysqlformatdate.com is useful website for generating for code needed to format dates in mysql Link to comment https://forums.phpfreaks.com/topic/173688-solved-sql-datetime-data-type-help/#findComment-991179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.