KingOfHeart Posted December 7, 2009 Share Posted December 7, 2009 20091203192725 I only need to return the month and the day out of this string. I used substr to separate the data. How do I turn that output into date format. Do I use a bunch of if statements, or do I use Date();? I tried date but the output was wrong. It returned something like this January 06 and none of the dates are for January. Link to comment https://forums.phpfreaks.com/topic/184217-turn-this-string-into-dateformat/ Share on other sites More sharing options...
JAY6390 Posted December 7, 2009 Share Posted December 7, 2009 This will turn the date into the correct time (I assume it's 3rd December 2009 19:27:25 that the date should be) $subject = '20091203192725'; $result = preg_replace('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/s', '$1-$2-$3 $4:$5:$6', $subject); $time = strtotime($result); $time will then contain the date that you can use with the date function as you wish, such as echo date('Y M', $time); Link to comment https://forums.phpfreaks.com/topic/184217-turn-this-string-into-dateformat/#findComment-972589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.