chordsoflife Posted May 5, 2008 Share Posted May 5, 2008 I have a date column in a MySQL database and I call it onto a page with PHP but I don't want it in the format MySQL has it. It comes in 2008-02-22 and I want it two ways: 1. Feb 22, 2008 2. 022208 Any way to do that? Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/ Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2008 Share Posted May 5, 2008 Look at the MySQL DATE_FORMAT() function. Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533604 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 Should be SELECT DATE_FORMAT(date_column,'%b %e, %Y') FROM table_name and SELECT DATE_FORMAT(date_column,'%m%d%y') FROM table_name Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533605 Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 Your other option is to format on output using PHP date() function www.php.net/date Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533606 Share on other sites More sharing options...
chordsoflife Posted May 5, 2008 Author Share Posted May 5, 2008 Thanks for the replies. I've already stored all the data in an array, so I don't want to select anything from the database anymore. Basically, this is where I'm at: $concert['date'] = DATE_FORMAT($concert['date'],'%b %e, %Y'); But that doesn't work, of course. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533628 Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 Your other option is to format on output using PHP date() function www.php.net/date Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533630 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 No, just modify your SELECT statement...no need to do an EXTRA select. What is your SELECT statement? Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533631 Share on other sites More sharing options...
chordsoflife Posted May 5, 2008 Author Share Posted May 5, 2008 here's the who shabang (well... not all of it): //select the database I want mysql_select_db("archive", $connection); //store the database in an array $result = mysql_query("SELECT * FROM concerts"); //format the date correctly $concert['date'] = DATE_FORMAT($concert['date'],'%b %e, %Y'); //spit out one result in this format at a time while($concert = mysql_fetch_array($result)) { echo " Barand- I'm looking into doing it with PHP too, I'm just not sure how to format it and keep getting errors, but I'm trying to work through it, so I'll learn. Super newbie here with a strong desire to learn. Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533640 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 //select the database I want mysql_select_db("archive", $connection); //store the database in an array $result = mysql_query("SELECT *,DATE_FORMAT(`date`,'%b %e, %Y') as fdate FROM concerts"); //spit out one result in this format at a time while($concert = mysql_fetch_array($result)) { echo $concert['fdate']; Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533643 Share on other sites More sharing options...
rhodesa Posted May 5, 2008 Share Posted May 5, 2008 or with php... //select the database I want mysql_select_db("archive", $connection); //store the database in an array $result = mysql_query("SELECT * FROM concerts"); //spit out one result in this format at a time while($concert = mysql_fetch_array($result)) { echo date('M j, Y',strtotime($concert['date'])); Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533645 Share on other sites More sharing options...
chordsoflife Posted May 5, 2008 Author Share Posted May 5, 2008 Awesome, thanks, worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/104230-solved-format-mysql-date/#findComment-533656 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.