Time is an interval, so you can save it in seconds.
The only thing is that seconds are not an object, and you cannot give it convenient functions, and it does not support a certain number of minutes.
For example, you use a time like 45:61:59 , after converting it to seconds, you will not be able to convert it back to this format.
PHP solves these problems using DateInterval
41:61:45 will be saved as
$interval = new DateInterval('PT41H61M45S');
The problem is that DateInterval not as easy to use or useful as it could, so why not create your own class?
Here I created it just for you (or someone else)
(I know I'm late, but this question still pops up in SERP)
class Time extends DateInterval { const SEC_IN_MINUTE = 60; const SEC_IN_HOUR = 3600; const SEC_IN_DAY = 86400; const SEC_IN_YEAR = 31536000; private $interval, $time;
Now you can take MySQL time and easily do whatever you want with it.
$time = new Time('864:23:59'); $seconds = $time->toSeconds(); $formatted_time = $time->reformat('%d days %h:%i:%s');
Feel free to edit this and make it shorter or better.
Timo Huovinen
source share