Hello! I create a time tracker in PHP, and I have to work a lot with time and dates. Faced with the problem of subtracting dates, if you take two DateTime objects, then as a result there is a DateInterval object from which you also need to take time, how to do it?

    1 answer 1

    Convert both values ​​to a Unix timestamp, subtract and convert back

    $date1 = '2018-03-01'; $date2 = '2018-03-02'; $result = strtotime($date2) - strtotime($date1); echo date('Ym-d', $result);