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.
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.
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));
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'));
Do something like this:
dateTime = new DateTime('YYYYMMD');
echo $dateTime->format('M jS Y');
i.e.
dateTime = new DateTime('20100808');