Home   Best Sellers   Blogging   Coding & Design   Technology   SEO   Travel & living   Career   Videos   Tips   Calculators     
Home  »     »     »  PHP function to convert duration into seconds

PHP function to convert duration into seconds

Tuesday, November 9, 2010

 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 

?>



How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
PHP function to convert duration into seconds.




Share this!




comments powered by Disqus

This Weeks 7 Popular Posts


Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   



Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »