Calculate difference between two PHP dates [duplicated]

1

I want to know the difference in days between two dates given in the format:

2018/01/05

PHP Code:

$diferencia_dias = $check_in->diff($check_out);
echo $diferencia_dias->format('%R%a días');

Error:

Fatal error: Call to a member function diff() on a non-object
    
asked by omaza1990 02.01.2018 в 18:12
source

1 answer

2

The way to do it is as follows: Source: PHP Documentation

<?php
    $fecha1 = new DateTime('2009-10-11');
    $fecha2 = new DateTime('2009-10-13');
    $resultado = $fecha1->diff($fecha2);
    echo $resultado->format('%R%a días');
?> 
    
answered by 02.01.2018 в 18:20