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:

Translate to de es fr it pt ja

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

The author does not allow comments to this entry

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options