2

I get several dateTime informations through an API. It's format is like P29DT48M56.941999S for example. I would like to convert it with to a readable sting using DateInterval::format. My snippet looks like

$interval = new DateInterval('P29DT48M56.941999S');
echo $interval->format(' %d days, %I minutes');

Unfortunally, I get this error:

PHP Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (P29DT48M56.941999S)'

What's wrong and how can I fix it?

Dong3000
  • 566
  • 2
  • 7
  • 24
  • I suspect your fractional seconds is the problem - http://stackoverflow.com/questions/12817172/add-10-5-seconds-with-dateinterval – Mark Baker Apr 06 '16 at 16:20
  • 2
    I see, so one has to remove the microseconds information before formatting. `preg_replace("'/.([0-9]{5,6})/'", "", "P29DT48M56.941999S")` works fine! – Dong3000 Apr 06 '16 at 17:32

0 Answers0