[SOLVED] Convert String From RSS Feed - Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
submike
Forum Newbie
Posts: 10
Joined: Wed Sep 01, 2004 10:12 am

Convert String From RSS Feed - Date

Post by submike »

I need some help converting the following date from a RSS feed into a more user-friendly date format.

From RSS Feed:
2004-09-17T00:00:00

Ideally, I would like it to appear as follows:
September 17, 2004

If that's too complicated, the following works too:
09-17-2004

Thanks in advance for any help,
Mike
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

What code do you have so far?
submike
Forum Newbie
Posts: 10
Joined: Wed Sep 01, 2004 10:12 am

Post by submike »

I think I solved my problem. Let me know if there's any way to streamline the code or a different approach.

Code: Select all

<?php

$month_arr = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

$start_date = "2004-09-17T00:00:00";
$today = explode("-",$start_date);
$gyear = $today[0];
$gmonth = (substr_replace($today[1], '', 0, -1) - 1);
$gday = substr_replace($today[2], '', 2);

echo $month_arr[$gmonth]." ".$gday.", ".$gyear;

?>
submike
Forum Newbie
Posts: 10
Joined: Wed Sep 01, 2004 10:12 am

Post by submike »

Here's the final approach I settled on.

Code: Select all

<?php

$month_arr = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

$start_date = "2004-09-17T00:00:00";
$gyear = substr($start_date, 0, 4);
$gmonth = (substr($start_date, 5, 2) - 1);
$gday = substr($start_date, 8, 2);

echo $month_arr[$gmonth]." ".$gday.", ".$gyear;

?>
Post Reply