Forum Moderators: coopster

Message Too Old, No Replies

Specific Date Structure to Unixtimestamp

         

asantos

4:18 pm on Jan 25, 2007 (gmt 0)

10+ Year Member



Hi. How do i get from this:
2007-01-25T15:19:29Z

To a unix timestamp?

I dont even know what kind of date structure that is (i am getting that value from a rss autogenerated file).

jatar_k

4:26 pm on Jan 25, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



explode on T results in part1 and part2

explode part1 on - gives yyyy mm dd

trim final char from part2

explode part2 on : gives hh mm ss

feed all of that into mktime

result is a timestamp

Little_G

4:55 pm on Jan 25, 2007 (gmt 0)

10+ Year Member



Hi,

Alternatively you could also use strtotime [php.net].

Andrew

jatar_k

4:59 pm on Jan 25, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, true

you might have to strip the T and Z, not sure, try it out

asantos

6:55 pm on Jan 26, 2007 (gmt 0)

10+ Year Member



thanks for the tips. is this optimized?

$d = '2007-01-26T09:26:07Z';
$d = str_replace('T',' ',$d);
$d = str_replace('Z',' ',$d);
echo strtotime($d);

jatar_k

7:06 pm on Jan 26, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



looks fine

does it work?

Little_G

7:41 pm on Jan 26, 2007 (gmt 0)

10+ Year Member



Hi,

is this optimized?

No, you don't need to remove the T and Z.

Andrew

asantos

9:08 pm on Jan 26, 2007 (gmt 0)

10+ Year Member



Little_G,
actually, if i dont remove the TZ, the return value is -1.

Little_G

11:53 pm on Jan 26, 2007 (gmt 0)

10+ Year Member



Hi,

What version of PHP are you using?

Andrew

asantos

4:29 am on Jan 27, 2007 (gmt 0)

10+ Year Member



sorry, forgot to tell you.
4.4

Little_G

2:09 pm on Jan 27, 2007 (gmt 0)

10+ Year Member



OK, fair enough, by version 5.2 that problem is fixed.

Andrew