Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Calcular diferença entre dois datetimes


Use as funções de data embutidas do 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");