A library and webservice I am using communicates time-intervals in ISO 8601 format: PnYnMnDTnHnMnS. I want to convert such formats to seconds. And vice versa. Seconds are a
What you are looking for is DateTime::diff
The DateInterval object representing the difference between the two dates or FALSE on failure as illustrated below:
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%d days');
Just use seconds instead of dates.
This is from http://www.php.net/manual/en/datetime.diff.php
For a reference to DateInterval see http://www.php.net/manual/en/class.dateinterval.php