A JM Posted August 18, 2009 Share Posted August 18, 2009 Is there a simple function for converting a date in "m/d/y" format to mysql datetime format of "y-m-d"? A JM, Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/ Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 Hiya mate, This works, Im sure there are easier ways but it works at the end of the day. <?php $change = "17/08/2009"; list($date, $month, $year) = explode("/", $change); $date = $date . '-' . $month . '-' . $year; echo $date; ?> James. Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/#findComment-900588 Share on other sites More sharing options...
roopurt18 Posted August 18, 2009 Share Posted August 18, 2009 I'm not sure if strtotime() understand the m/d/y format, but I use date( 'Y-m-d H:i:s', strotime( $orig ) ) a lot. Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/#findComment-900626 Share on other sites More sharing options...
HoTDaWg Posted August 18, 2009 Share Posted August 18, 2009 this isnt the perfect solution but id just: <?php $string = 'd/m/y'; $newstring = explode('/',$string); array_reverse($newstring); $finalstring = implode('/',$newstring); ?> hope this helps! HoTDaWg Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/#findComment-900651 Share on other sites More sharing options...
ironhamster88 Posted August 18, 2009 Share Posted August 18, 2009 Or even.... <?php $old_date = '01/21/2009'; // or date('m/d/y') or whatever $new_date = date('Y-m-d', strtotime($old_date)); ?> ** edit ** aah that's pretty much what roopurt18 said, whoops :-P Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/#findComment-900755 Share on other sites More sharing options...
A JM Posted August 18, 2009 Author Share Posted August 18, 2009 Thanks for all the input. Link to comment https://forums.phpfreaks.com/topic/170762-solved-how-to-convert-dmy-ymd/#findComment-901049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.