After moving from one server to another, there was such an error, I just can not understand what the problem is. Help me please!

Fatal error: diff (): Unknown property (w) in /var/www/arashvg/data/www/all-payeer.ru/bonus.php on line 199

Here is the code

function diff(DateTime $datetime2, DateTime $datetime1 = null) { if (!isset($datetime1)) { $datetime1 = new DateTime('now'); } $interval = $datetime1->diff($datetime2, false); $days = $interval->days; // calculate seconds $interval->s = $datetime2->getTimestamp() - $datetime1->getTimestamp(); $interval->i = floor($interval->s / 60); $interval->h = floor($interval->s / (60 * 60)); $interval->d = $days; $interval->w = floor($days / 7); //На этой строке выдает ошибку $interval->m = floor($days / $datetime1->format('t')); return $interval; } 

    1 answer 1

    The documentation http://php.net/manual/ru/class.dateinterval.php has no indication of the week, perhaps the weeks were in the earlier version of PHP, then they were removed. You can do 2 things in this case:

    1. Find out the PHP version on the old server, and try to put it on the new one.

    2. Remove or replace outdated code.

    In addition, you set the weeks along with the days, which is wrong from the PHP point of view: http://php.net/manual/ru/dateinterval.construct.php

    W - weeks. Converted to days, so can not be used in conjunction with D.

    Well, the last question, I do not understand why this code, if you have already counted the interval here?

     $interval = $datetime1->diff($datetime2, false); 
    • The thing is, I need to get the interval in seconds. - arashvg
    • Then why not just calculate the difference in seconds? $datetime1->getTimestamp() - $datetime2->getTimestamp() - Crantisz
    • I figured it out, thanks! )) - arashvg