homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

date in xml to user friendly display

 3:01 pm on May 16, 2008 (gmt 0)

ive got an xml file i'm parsing and working great but i'm having a mare to convert the date into a user friendly display (nb i'm not a php expert)


gives me 2008-05-16T23:59:00+01:00

from the xml:

<status code="4">4</status>
<date type="updated">2008-05-08T22:57:31+01:00</date>
<date type="publish">2008-03-18T00:00:00+00:00</date>
<date type="expires">2008-05-16T22:30:00+01:00</date>
<date type="starts">2008-05-16T23:59:00+01:00</date>
<date type="ends">2008-05-17T06:00:00+01:00</date>

(event is the main wrapper)

i realise i have to convert it somehow but i dont know where to start - any help would be appreciated



 3:05 pm on May 16, 2008 (gmt 0)

you could split on T and end up with an ok date

what format do you want?


 3:09 pm on May 16, 2008 (gmt 0)

ideally i'd like eg: Mon 4th July - but i could live with getting rid of the time :)


 3:13 pm on May 16, 2008 (gmt 0)

split on T
then use strtotime [ca.php.net] to convert to timestamp
then feed it to strftime [php.net] and you can use whatever format you like


 3:22 pm on May 16, 2008 (gmt 0)

$thedate = '2008-05-16T23:59:00+01:00';
$thedate = split('T',$thedate);
$thedate = $thedate[0];
$thedate = strftime('%a %e %b',strtotime($thedate));
echo $thedate;


 3:35 pm on May 16, 2008 (gmt 0)

can i substitute
$thedate = '2008-05-16T23:59:00+01:00';


$thedate = .$event->meta->date[3];

as i've got a foreach

and then put $thedate in the echo statement ?

as i said i'm on a steep learning curve here ;)


 3:48 pm on May 16, 2008 (gmt 0)

>> can i substitute

yes, exactly

but you know, you could try it, if it breaks, whatever

if you don't ever break it how will you know how to fix it ;)


 3:51 pm on May 16, 2008 (gmt 0)

it worked out :)

i put this inside the foreach

$thedate = $event->meta->date[3];
$thedate = split('T',$thedate);
$thedate = $thedate[0];
$thedate = strftime('%a %e %b',strtotime($thedate));

and then simply put $thedate in the echo

thank you :)


 3:56 pm on May 16, 2008 (gmt 0)

glad to help


 6:54 pm on May 16, 2008 (gmt 0)

I'd say that 2008-05-16 is a pretty friendly format. It can't be confused with any other format.

With a four-digit year, it's always Year-Month-Day.

It has been an International Standard for nearly 40 years.

The US signed up in 1967. See NIST FIPS 4-1 and ANSI X3.30 etc.


 5:31 pm on May 20, 2008 (gmt 0)

Yeah, you really don't have to split the date here as that format is acceptable.
How to parse 2006-10-30T00:00:00-08:00 [webmasterworld.com]

If you wanted to get the english ordinal suffix you could use the date [php.net] function rather than strftime().

print date('D jS F', strtotime($event->meta->date[3]));

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved