tags:

views:

59

answers:

3

I have an array of dates which are in the format 20100808 (YYYYMMD). How can i change this into August 08 2010? I am using php.

I cannot change the date array format. It will be in 20100808 only.

A: 

You can use strtotime to convert the string to a timestamp, and date to format the timestamp as a new string:

$dates = array(20100808, ...);
foreach($dates as $date)
    echo date("F d Y", strtotime($date));
Michael Mrozek
A: 

Assuming you are using PHP 5.3:

$date = date_create_from_format('Ymd', '20100808');

echo $date->format('F d Y')

If not you could try:

echo date('F d Y', strtotime('20100808'));
Michael Robinson
thanks ... made some modifications according to my code and your second solution clicked.
Scorpion King
A: 

Do something like this:

dateTime = new DateTime('YYYYMMD');
echo $dateTime->format('M jS Y'); 

i.e.

dateTime = new DateTime('20100808');
NinjaCat