Answer the question
In order to leave comments, you need to log in
How to multiply time by a number?
It seems like a simple topic, but I can’t figure it out ...
The database contains data in the time format. It is required to take this data, multiply it by an integer and output/save in the format time (H:i:s)
Tried like this
tTime = date('H:i:s', StrToTime($dTime) * 5);
but for some reason if for example dTime=00:01:00 then the result is 20:05:00
Answer the question
In order to leave comments, you need to log in
You need to multiply the time by 5! O_O
Maybe minutes, hours or something else?
multiplying time() you multiply by years months days, hours, minutes and seconds, it is quite logical that at the output you will get different times even with a difference of 1 second!
For multiplication use for example mktime
I don't know if I did it right...
private function timeToSecond($time)
{
$part = explode(':', $time);
$second = $part[0]*3600 + $part[1]*60 + $part[2];
return $second;
}
private function secondToTime($second)
{
$hours = intdiv($second, 3600);
$minutes = intdiv(($second - $hours*3600), 60);
$seconds = $second - $hours*3600 - $minutes*60;
return date('H:i:s', mktime($hours,$minutes,$seconds));
}
tTime = self::secondToTime(self::timeToSecond($dTime) * 5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question