searls03 Posted March 17, 2011 Share Posted March 17, 2011 How can I convert a database time to mm/dd/yyyy from yyyy-mm-dd when pulling from database to display, and vice versa when from form to database? Link to comment https://forums.phpfreaks.com/topic/230958-convert-database-yyyy-mm-dd-to-mmddyyyy/ Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 Retrieving: use the MySQL function DATE_FORMAT() Inserting depends on how the date is formatted to begin with, and whether you're validating and enforcing that format. Link to comment https://forums.phpfreaks.com/topic/230958-convert-database-yyyy-mm-dd-to-mmddyyyy/#findComment-1188889 Share on other sites More sharing options...
searls03 Posted March 17, 2011 Author Share Posted March 17, 2011 It will always be mm/dd/yyyy for it will be a calendar that pops up to make sure it is that format............ Link to comment https://forums.phpfreaks.com/topic/230958-convert-database-yyyy-mm-dd-to-mmddyyyy/#findComment-1188894 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 Then using two php functions, date() and strtotime() will work. $date_string = '12/31/2004'; $formatted_date = date( 'Y-m-d', strtotime($date_string) ); Link to comment https://forums.phpfreaks.com/topic/230958-convert-database-yyyy-mm-dd-to-mmddyyyy/#findComment-1188897 Share on other sites More sharing options...
searls03 Posted March 17, 2011 Author Share Posted March 17, 2011 Where exactly will I put these in my PHP code? Link to comment https://forums.phpfreaks.com/topic/230958-convert-database-yyyy-mm-dd-to-mmddyyyy/#findComment-1188899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.