Guest Posted November 27, 2009 Share Posted November 27, 2009 Hi guys, I would like to display on my webpage a DATE item from one of my database using PHP, but I would like to format it like "15 December 2009" instead of 2009-12-15. Can anyone help me? Thanks in advance for your help. Cheers, Chris Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2009 Share Posted November 27, 2009 Use the mysql DATE_FORMAT() function directly in your query to get a DATE into any format you want - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/#findComment-966436 Share on other sites More sharing options...
Guest Posted November 27, 2009 Share Posted November 27, 2009 I tried that but apparently not well as I don't get anything. Here is what I tried: <?php $sql = "SELECT DATE_FORMAT(event_start_date,'%d %b %y') as event_start_date FROM events WHERE id = '2'"; $result = mysql_query($sql); echo $result; ?> Any idea what I did wrong? Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/#findComment-966440 Share on other sites More sharing options...
eugene2009 Posted November 27, 2009 Share Posted November 27, 2009 Yes, theres a few errors that I spot. May I please see your full code? Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/#findComment-966577 Share on other sites More sharing options...
akitchin Posted November 27, 2009 Share Posted November 27, 2009 are you trying to actually echo the results? if so, you'll need to use a MySQL fetching function to extract the results from the resource ID mysql_query() returns. Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/#findComment-966578 Share on other sites More sharing options...
Guest Posted November 27, 2009 Share Posted November 27, 2009 Thanks a lot, it works fine now... Quote Link to comment https://forums.phpfreaks.com/topic/183117-how-to-display-mysql-date-in-a-better-looking-way/#findComment-966582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.