Welcome to WebmasterWorld Guest from 54.146.59.202

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

date in xml to user friendly display

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

5+ Year Member



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)

.$event->meta->date[3].

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

from the xml:

<meta>
<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>
</meta>

(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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

5+ Year Member



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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



$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)

5+ Year Member



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

for

$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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



>> 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)

5+ Year Member



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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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]));
 

Featured Threads

Hot Threads This Week

Hot Threads This Month