note 74716 deleted from function.time by bjori

From: Date: Thu, 26 Apr 2007 10:16:15 +0000
Subject: note 74716 deleted from function.time by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125884@lists.php.net to get a copy of this message
Note Submitter: jason at thinkingman dot org ---- Here you go. You can specify how much you wanna see -- years, days, hours, minutes or seconds. Returns an Array containing a String and individual time values. Usage: $tl = calc_tl($unixTime); $tl = calc_tl($startTime, $stopTime, [detail]); <?php function calc_tl($t, $sT = 0, $showMe = 'y') { if((int)$sT) { $t = ($sT - $t); } $r = array(); if($t > 0) { $sY = 31536000; $sD = 86400; $sH = 3600; $sM = 60; switch(strtolower($showMe)) { case 'y': $y = ((int)($t / $sY)); $t = ($t - ($y * $sY)); $r['string'] .= "{$y} years "; $r['years'] = $y; case 'd': $d = ((int)($t / $sD)); $t = ($t - ($d * $sD)); $r['string'] .= "{$d} days "; $r['days'] = $d; case 'h': $h = ((int)($t / $sH)); $t = ($t - ($h * $sH)); $r['string'] .= "{$h} hours "; $r['hours'] = $h; case 'm': $m = ((int)($t / $sM)); $t = ($t - ($m * $sM)); $r['string'] .= "{$m} minutes "; $r['minutes'] = $m; case 's': $s = $t; $r['string'] .= "{$s} seconds"; $r['seconds'] = $s; break; } } return $r; } $start_time = time(); $stop_time = mktime(12,00,0,12,31,2019); $tl = calc_tl($start_time, $stop_time); print_r($tl); ?> OUTPUT: Array ( [string] => 12 years 253 days 22 hours 38 minutes 56 seconds [years] => 12 [days] => 253 [hours] => 22 [minutes] => 38 [seconds] => 56 )

« previous php.notes (#125884) next »