Created
          May 4, 2012 21:21 
        
      - 
      
 - 
        
Save md2perpe/2597798 to your computer and use it in GitHub Desktop.  
    Convert seconds to years, days, hours, minutes and seconds
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function sec2time($time) | |
| { | |
| if(!is_numeric($time)) | |
| return false; | |
| $value = array( | |
| 'seconds' => 60, | |
| 'minutes' => 60, | |
| 'hours' => 24, | |
| 'days' => 365, | |
| ); | |
| foreach ($value as $part => $count) | |
| { | |
| $value[$part] = $time % $count; | |
| $time = floor($time / $count); | |
| } | |
| $value['years'] = $time; | |
| return $value; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
First version taken from from http://www.catswhocode.com/blog/10-super-useful-php-snippets
Later versions are my own.