coldfission Posted June 9, 2007 Share Posted June 9, 2007 I need to change the date format from a table that got it's date from a different souce. This format looks like this: 6/1/2007 15:26:00 It needs to look like this 2007-06-01 15:26:00. What PHP function would i use for this and how would it be done? This is the last step to a month long project I have been working on and it needs to be completed very soon. Any help would be appreciated thanks Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/ Share on other sites More sharing options...
AndyB Posted June 9, 2007 Share Posted June 9, 2007 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Looks like you can do it directly in MySQL with str_to_date Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/#findComment-271503 Share on other sites More sharing options...
cooldude832 Posted June 9, 2007 Share Posted June 9, 2007 Try that: $date = explode("-",$row[ 'Date']); $formatted_date = $date[2]."-".$date[0]."-".$date[1]; Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/#findComment-271505 Share on other sites More sharing options...
cooldude832 Posted June 9, 2007 Share Posted June 9, 2007 you might need to say $temp = explode(" ",$date[2]); to get the day away from the time Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/#findComment-271507 Share on other sites More sharing options...
coldfission Posted June 9, 2007 Author Share Posted June 9, 2007 STR_TO_DATE worked out great. thanks Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/#findComment-271510 Share on other sites More sharing options...
coldfission Posted June 11, 2007 Author Share Posted June 11, 2007 SELECT SQL_CALC_FOUND_ROWS ID, STR_TO_DATE( modified, '%m/%d/%Y %H:%i:%s' ) AS modified, NULL AS organization, CONCAT( f_name, ' ', l_name ) AS name, address, city, state, zip, country, phone, email, payment_method, total, 'tack-wholesale.com' AS source FROM tack_orders WHERE '9999' >= modified AND modified >= '2005' AND 100000000000 >= total AND total >=0 ORDER BY modified ASC LIMIT 0 , 35 This did not return all dates after 2005. How would i get this to work? Link to comment https://forums.phpfreaks.com/topic/54897-solved-change-date-string-to-adapt-to-existing/#findComment-272333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.