pioneerx01 Posted August 13, 2012 Share Posted August 13, 2012 Hi, Lets say that I have a date in the format of YmdHis (reads: 20120813005549) and I want to convert it into D, M d, Y at g:i:s A (reads: Mon, Aug 13, 2012 at 12:55:49 AM) Is there a way to do this automatically or semi-automatically with some code? Thanks Link to comment https://forums.phpfreaks.com/topic/267004-how-do-i-convert-dates-between-formats/ Share on other sites More sharing options...
trq Posted August 13, 2012 Share Posted August 13, 2012 You'll need a valid date format in the first place, but yeah, take a look at the datetime functions. http://php.net/manual/en/ref.datetime.php Link to comment https://forums.phpfreaks.com/topic/267004-how-do-i-convert-dates-between-formats/#findComment-1368925 Share on other sites More sharing options...
xyph Posted August 13, 2012 Share Posted August 13, 2012 Here's a bit of a start to help you out. This will split the string into it's components <?php $date_str = '20120813005549'; list( $year1, $year2, $month, $day, $hour, $min, $sec ) = str_split($date_str, 2); $year = $year1.$year2; echo "$year - $month - $day $hour:$min:$sec"; ?> Link to comment https://forums.phpfreaks.com/topic/267004-how-do-i-convert-dates-between-formats/#findComment-1369011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.