PHP Dates and Datetimes from ISO Dates

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi all,

I was wondering if someone could help me out with a question about PHP
Dates. I would like to pass a date to PHP via a query string, using
ISO 8601 formatting ("2008-09-15T00:00:00Z"). I then would like to be
able to manipulate the date in PHP, and do things like printing out
the hour, adding seconds, etc. So far the best I've come up with is
use PHP's "strptime" function to get an array of the date components:

$ts = "2008-09-15T00:00:00Z"
$format = '%Y-%m-%dUTC%H:%M:%S';
$d = strptime(date($ts), $format);
$mon  = str_pad($d['tm_mon'] + 1, 2 , "0", STR_PAD_LEFT);

Can anyone tell me a better way of working with dates in PHP? I've dug
around in the manual and found several objects (Date, Datetime, etc),
but am not sure which is best suited for what kinds of jobs, or how to
even get from an ISO date to a Datetime object for instance.

Any suggestions would be greatly appreciated.


Re: PHP Dates and Datetimes from ISO Dates

.oO(Keith Hughitt)

Quoted text here. Click to load it

You're welcome.


Site Timeline