views:

42

answers:

3

I have this: 2010-04-08T01:01:00Z

I want to remove the 'T' and everything behind it as well.

Also I would like to rewrite the date into this format: 08-04-2010

How can I do this the easiest way?

Thanks

+1  A: 

I think strftime is what you are looking for.

For example, strftime('%c') gives you something like 'Thur Apr 21, 2011 8:00am' -- you just need to find the format you want. Of course, having said that, I was assuming that your timestamp is not just a string. If it is, this might not help you at all.

MJB
+5  A: 
date("d-m-Y",strtotime("2010-04-08T01:01:00Z"))
bateman_ap
A: 

How about a simple

substr($t, 0, 10);

? The date part is always 10 characters long (even ASCII), as long as it's an ISO date.

Reversing order is a bit trickier, but doable, too:

$new = join("-", array_reverse(explode("-", substr($t, 0, 10))));

There's nothing wrong with the other, date based answers, but this would work, too.

Boldewyn