refiking Posted May 12, 2009 Share Posted May 12, 2009 How can I reformat the date from mysql format to M d Y format? Here is what I did so far: $mon = date("M d Y", $row['mon']); $exp = date("M d Y", $row['exp']); Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/ Share on other sites More sharing options...
The Little Guy Posted May 12, 2009 Share Posted May 12, 2009 If you don't already, you should format the rows as Unix timestamps. $mon = date("M d Y", strtotime($row['mon'])); $exp = date("M d Y", strtotime($row['exp'])); Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832715 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 What is $row['mon']? Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832720 Share on other sites More sharing options...
refiking Posted May 12, 2009 Author Share Posted May 12, 2009 they are dates from the database For example, one record is 2005-03-12 Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832726 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 Use SQL - SELECT DATE_FORMAT(mon, '%M %d %Y') AS mon, DATE_FORMAT(exp, '%M %d %Y') AS exp FROM table; Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832730 Share on other sites More sharing options...
refiking Posted May 12, 2009 Author Share Posted May 12, 2009 That won't work because I need to have it unformatted as well as formatted. However, I decided to use the strtotime function, just in case anyone else runs into the same dilemna. Here's my code: $mon = date("M d Y",strtotime($row['mon'])); Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832734 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 It would work if you change it to - SELECT DATE_FORMAT(mon, '%M %d %Y') AS formatted_mon, DATE_FORMAT(exp, '%M %d %Y') AS formatted_exp FROM table; Link to comment https://forums.phpfreaks.com/topic/157869-solved-reformat-date/#findComment-832738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.