Skip to content

PHP DateInterval::__construct(): Unknown or bad format - trouble with ISO 8601 Date Format

To keep it short, you code is failing because of an message like:


DateInterval::__construct(): Unknown or bad format (P0Y2M7DT-1H7M14S) 
Why? Well it is obvious if your eyes are fresh, otherwise well hidden.
The bad thing is the "-" between "T" and "1". Cover your string by let it run through str_replace('-', '', $dateIntervalAsString) and you are a step closer to pretty safe code.
How can this happen?
First of all, by strange data and secondly by trying to solve the date format on your own. Really, old code is your enemy at this point.

For the sake of input and output, here are some important links: