Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Add Up Hours, Minutes, Seconds

Tags:

php

Given a series of hours, minutes, and seconds (ex: 01:30:00 or 00:30:00), I would like to add up each and convert the sum to seconds.

For example, if the total time is 02:30:00, the total time should be in seconds.

Thanks!

like image 235
Ted Sum Avatar asked Dec 08 '25 12:12

Ted Sum


1 Answers

$timestr = '00:30:00';

$parts = explode(':', $timestr);

$seconds = ($parts[0] * 60 * 60) + ($parts[1] * 60) + $parts[2];
like image 72
Marc B Avatar answered Dec 10 '25 00:12

Marc B