C
C
Crash2018-03-29 09:56:20
PHP
Crash, 2018-03-29 09:56:20

Is it possible to add time intervals in MySQL TIME format using standard PHP tools?

My table has a column in the HH:MM:SS format, which indicates the recommended time to complete a particular task. You need to add these values ​​and get the result in the same format. Is it possible to do this with standard PHP tools for working with time, or will you have to translate everything into seconds, and then back?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Crash, 2018-03-29
@Bandicoot

Found the solution myself. Such operations were within the competence of MySQL)

SELECT sec_to_time(sum(time_to_sec(ex_time))) as total_time FROM table_name;

Q
Quark_rgb, 2018-03-29
@Quark_rgb

Maybe it will fit diff
something like this

$datetime1 = date_create('12:00:00');
$datetime2 = date_create('13:20:30');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%H ч %i м %s с');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question