Function to convert duration into seconds. Function accepts duration in the format hour:minutes:seconds (hh:mm:ss) and this is converted into seconds.
function convertDurationToSeconds($dur){
// the input should be in format hh:mm:ss (example: 01:05:09)
$DurationInSeconds=0;
// checks the presence of ":" twice
if( substr_count($dur,":" ) == 2 ){
$arrDuration= @explode( ":",$dur );
if( is_array( $arrDuration ) && count($arrDuration) == 3 ){
// multiplies the hour part with 3600 , multiplies the minutes part with 60 and add all this with second part value
$DurationInSeconds = ( intval( $arrDuration[0] ) * 3600 ) + ( intval( $arrDuration[1] ) * 60 ) + intval( $arrDuration[2] );
}
}
return $DurationInSeconds;
}
// End of function
?>
function convertDurationToSeconds($dur){
// the input should be in format hh:mm:ss (example: 01:05:09)
$DurationInSeconds=0;
// checks the presence of ":" twice
if( substr_count($dur,":" ) == 2 ){
$arrDuration= @explode( ":",$dur );
if( is_array( $arrDuration ) && count($arrDuration) == 3 ){
// multiplies the hour part with 3600 , multiplies the minutes part with 60 and add all this with second part value
$DurationInSeconds = ( intval( $arrDuration[0] ) * 3600 ) + ( intval( $arrDuration[1] ) * 60 ) + intval( $arrDuration[2] );
}
}
return $DurationInSeconds;
}
// End of function
?>
Comments
Post a Comment