note 74742 deleted from function.time by bjori

From: Date: Thu, 26 Apr 2007 10:16:00 +0000
Subject: note 74742 deleted from function.time by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125883@lists.php.net to get a copy of this message
Note Submitter: jason at thinkingman dot org ---- Ok -- because Weeks are important too, I've added them into the function. <?php // calc_tl (calculate time-lapse) // Written by J.C. // April 24th, 2007 // // Usage: // $tl = calc_tl($unixTimeStamp, [$unixStopTime], [viewScope]) // // Returns an Array. // // License: Free to use, disect, add-to, remove-from, modify, // convert or just play with. May not be used if you // are an evil bad person. function calc_tl($t, $sT = 0, $showMe = 'y') { if((int)$sT) { $t = ($sT - $t); } $r = array(); if($t > 0) { $sY = 31536000; $sW = 604800; $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 'w': $w = ((int)($t / $sW)); $t = ($t - ($w * $sW)); $r['string'] .= "{$w} weeks "; $r['weeks'] = $w; 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; } ?>

« previous php.notes (#125883) next »