sql >> Base de Datos >  >> RDS >> Mysql

Calcular la diferencia entre dos fechas y horas

Use las funciones de fecha integradas de PHP:

<?php
    $start_time = "Y-m-d H:i:s"; // fill this in with actual time in this format
    $end_time = "Y-m-d H:i:s"; // fill this in with actual time in this format

    // both of the above formats are the same as what MySQL stores its
    // DATETIMEs in

    $start = new DateTime($start_time);
    $interval = $start->diff(new DateTime($end_time));

    echo $interval->format("d \d\a\y\s h \h\o\u\r\s");