Mr Chris Posted February 4, 2009 Share Posted February 4, 2009 Hello, I have a date set in a database in a field called published like so: 2009-01-23 08:00:00 and I query the database to get the site out in a set format like so: Friday, 23rd January, 2009 $SQL = "SELECT *, DATE_FORMAT(published, '%W, %D %M, %Y') AS formatted_date from blah" $result = mysql_query($SQL) OR die(mysql_error()); $formatted_date = $row['formatted_date']; However, I also want to get the date out in the published field in following format as well: yyyy/mm/dd How can I do this please? Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/ Share on other sites More sharing options...
ngreenwood6 Posted February 4, 2009 Share Posted February 4, 2009 Try this: $SQL = "SELECT *, DATE_FORMAT(published, '%Y/%m/%d') AS formatted_date from blah" I used this page as a reference http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/#findComment-754642 Share on other sites More sharing options...
Mr Chris Posted February 4, 2009 Author Share Posted February 4, 2009 Thanks, but I want Both sets of dates pulled out. Any other ideas? Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/#findComment-754647 Share on other sites More sharing options...
ngreenwood6 Posted February 4, 2009 Share Posted February 4, 2009 oh sorry I thought you were trying to figure out how to do it lol. wouldn't this work: $SQL = "SELECT *, DATE_FORMAT(published, '%W, %D %M, %Y') AS formatted_date, DATE_FORMAT(published, '%Y/%m/%d') AS another_formatted_date from blah" $result = mysql_query($SQL) OR die(mysql_error()); $formatted_date = $row['formatted_date']; $another_formatted_date = $row['another_formatted_date']; Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/#findComment-754649 Share on other sites More sharing options...
Mr Chris Posted February 4, 2009 Author Share Posted February 4, 2009 thanks good idea! I was thinking of doing some date conversion here ie: $published = $row['published']; $newdate = convert here somehow from $published variable; But that seems to work Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/#findComment-754670 Share on other sites More sharing options...
ngreenwood6 Posted February 4, 2009 Share Posted February 4, 2009 If the question has been answered please mark thread as resolved. Link to comment https://forums.phpfreaks.com/topic/143824-solved-formatting-a-date-pulled-out-of-mysql-in-php/#findComment-754674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.