Tuesday 10 May 2016

PHP: String HH:MM:SS to hours (float)

Hello,

How to parse string with format HH:MM:SS to hours:

$string = '01:58:03';
sscanf($string, "%d:%d:%d",  $hours, $minutes, $seconds);
$hours = $hours + $minutes/60 + $seconds/3600;

Best regards!
 

No comments:

Post a Comment