There is a sql table, the column has the format 'time'. The record contains the value 00:03:01, and I pass it to the variable. How do I get the number of seconds from this variable?

    1 answer 1

    In PHP, there are classes DateTime ( http://php.net/manual/ru/class.datetime.php ), DateInterval ( http://php.net/manual/ru/class.dateinterval.php ) and a few others, which allow you to perform most of the necessary operations with time and dates.

    In your case, something like:

    $dt = new DateTime('00:03:01'); echo (int)$dt->format('s'); // выводим отформатированную дату, показывая только секунды, и преобразуем в целое число 
    • It takes a sum of seconds, i.e. 181 - Alexander Yushko
    • 2
      So make by analogy: (int)$dt->format('s') + 60 * (int)$dt->format('i') + 3600 * (int)$dt->format('H'); - Gino Pane
    • Gino Pane, thank you - Alexander Yushko