So I'm passing a variable from Javascript into PHP that marks the Current Time on a video being played. And I have no problem passing that decimal into mySQL, but I don't want it in decimal form. The Javascript .currentTime function seems to output a float or a double in seconds. And when I try to pass that into my VARCHAR in mySQL I get an empty spot, not null, just blank. It works if I remove this code and just switch $currentTimeRaw for $currentTime. That effectively bypasses this piece of code. So I know the problem is here but I can't figure out what I did wrong.
$currentTimeRAW = $_GET['currentTime'];
$minutes = 0;
$hours = 0;
while($currentTimeRAW >= 3600){
$currentTimeRAW = $currentTimeRAW - 3600;
$hours++;
}
while($currentTimeRAW >= 60){
$currentTimeRAW = $currentTimeRAW - 60;
$minutes++;
}
if($hours>0){
$currentTime = $hours.':'.$minutes.':'.$currentTimeRAW;
} else if ($hours=0){
$currentTime = $minutes.':'.$currentTimeRAW;
} else if ($hours=0 && $minutes=0){
$currentTime = $currentTimeRAW;
}
source https://stackoverflow.com/questions/68595751/php-converting-decimal-time-to-hms
Comments
Post a Comment