Forum Moderators: coopster

Message Too Old, No Replies

How to parse 2006-10-30T00:00:00-08:00

         

tyrone04

11:03 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



I have a string that has a format like this 2006-10-30T00:00:00-08:00. What time function can I use to parse it into day, month, date?

coopster

12:24 am on Dec 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That is an acceptable date and time format as specified in ISO 8601 [w3.org] so the PHP strftime() and strtotime() functions should work just fine.
$timestamp = '2006-10-30T00:00:00-08:00'; 
print strftime [php.net]('%d-%m-%Y', strtotime [php.net]($timestamp));
// 30-10-2006
print strftime('%A, %B %d, %Y', strtotime($timestamp));
// Monday, October 30, 2006

tyrone04

1:02 am on Dec 22, 2007 (gmt 0)

10+ Year Member



How come strftime() doesn't offer a format for day or month without leading zeros?

So it'd just be 1, not 01.

jatar_k

1:46 am on Dec 22, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



%e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')

I don't believe there is one for month though

mikesmith76

7:11 pm on Dec 23, 2007 (gmt 0)

10+ Year Member



If you're using php5 try [php.net...] as well.