PHP DateInterval bug

Today, I have wasted 5 hours on one of my websites trying to get a php Date function to work.
According to the WebFX tutorial, as well as the php manual, the following code fragment is totally legit:

$Duration = new DateInterval( "P1Y2M3DT4H5M6S" );

But that line alone crashes my whole page. There are no error messages nor do the log files show anything. The support AI page (I wonder about its IQ?) chats about PHP5.6 and CGI, but I changed to 7.2 and that makes no difference at all.
If you are wondering, whether I am miffed, you are right.

Does DateInterval work in isolation? The following works for me with PHP 7.2.24 on Shared Hosting.



$Duration = new DateInterval( "P1Y2M3DT4H5M6S" );


object(DateInterval)#2 (16) {

Thanks for assistance. After another 4 1/2 hours I finally figured it out:
The problem is not the time interval. for date_add to work, one has to create the DateTime object not with the ‘strtotime()’ function, but with ‘date_create()’.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.