websteve Posted August 14, 2010 Share Posted August 14, 2010 Can someone tell me how to convert a MySQL date such as 2010-08-13 into the the US format, such as 8/13/2010, and also the reverse using PHP? I can't seem to find the right functions. Thanks! Link to comment https://forums.phpfreaks.com/topic/210704-php-date-conversion/ Share on other sites More sharing options...
trq Posted August 14, 2010 Share Posted August 14, 2010 Why use php? mysql has a perfectly good DATE_FORMAT() function. Link to comment https://forums.phpfreaks.com/topic/210704-php-date-conversion/#findComment-1099150 Share on other sites More sharing options...
websteve Posted August 14, 2010 Author Share Posted August 14, 2010 Thanks for the reply, but what if I want to display the converted data to the screen? I'm trying this code (below) that searches all rows between 2 dates, using STR_TO_DATE(). Doesn't seem to work correctly, but besides getting this to work right, the end result I want is to echo the converted date to the display. Sorry for sounding confused, I used to work in PHP a few years ago and am just starting to get back into it. This is the code I have now. I know it is not correct. $datefilter = '%m/%d/%y/'; $Res_pur = "SELECT * FROM Purchasing WHERE Date BETWEEN STR_TO_DATE('$beg_date', '$datefilter') AND STR_TO_DATE('$end_date', '$datefilter')"; $Results_pur = mysql_query($Res_pur)or die('Could Not Access Purchasing Table: ' . mysql_error()); while ($Results_pur_Arr = mysql_fetch_array($Results_pur)) { echo '<tr><td>'. $Results_pur_Arr['ID'] . '</td><td>'. $Results_pur_Arr['Date'].'</td><td>'. $Results_Arr['Item'].'</td><td>'.$Results_Arr['Description'].'</td></tr>'; } Link to comment https://forums.phpfreaks.com/topic/210704-php-date-conversion/#findComment-1099154 Share on other sites More sharing options...
trq Posted August 14, 2010 Share Posted August 14, 2010 but what if I want to display the converted data to the screen? Instead of using the wildcard * (which is never a good idea), specify the fields you want and use the DATE_FORMAT() function around your Date field. Link to comment https://forums.phpfreaks.com/topic/210704-php-date-conversion/#findComment-1099156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.