Hey everyone, did some research to try to figure out the issue, but still having issues. Hoping for some help. I started my reading here : http://php.net/manual/en/function.strtotime.php Basically I have a string variable that is an 8 digit number: ex- MMDDYYYY All I want to accomplish is taking the variable $date and displaying it in plain text so it would work like this: $date = "10142010" when I use print or echo on my page, I want that variable to display as October 10, 2010. Any pointers?
hi, your variable, $date = 10142010; Now seperate the first two digits by using, $rest = substr($date, 0, -6); $dateandyear = substr($date,-6); it will returns the first two digits, place a if() statement, if($rest == 01) { $rest = January; } else if($rest == 02) { $rest = Feb; } . . . repeate it for all 12 months, now echo $rest.' '. $dateandyear; the output will be, October 10 2010
hey, the following shall sort it neatly.. $date = '10142010'; $month = substr($date, 0, 2); $day = substr($date, 2, 2); $year = substr($date, 4, 4); $new_date = date('F, d Y', mktime(0, 0, 0, $month, $day, $year)); PHP:
EDIT: I retract my previous post- I didnt know I received another reply already with the needed info. Thanks mastermunj!
$date = '10142010'; preg_match('#^(?P<month>\d{2})(?P<day>\d{2})(?P<year>\d{4})$#D', $date, $digits); $timestamp = strtotime("{$digits['month']}/{$digits['day']}/{$digits['year']}"); echo date('F, d Y', $timestamp); PHP: