note 74716 added to function.time

From: Date: Tue, 24 Apr 2007 21:40:43 +0000
Subject: note 74716 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-125842@lists.php.net to get a copy of this message
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 ) ---- Server IP: 69.39.81.135 Probable Submitter: 71.128.119.221 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- https://master.php.net/note/edit/74716 Del: integrated -- https://master.php.net/note/delete/74716/integrated Del: useless -- https://master.php.net/note/delete/74716/useless Del: bad code -- https://master.php.net/note/delete/74716/bad+code Del: spam -- https://master.php.net/note/delete/74716/spam Del: non-english -- https://master.php.net/note/delete/74716/non-english Del: in docs -- https://master.php.net/note/delete/74716/in+docs Del: other reasons-- https://master.php.net/note/delete/74716 Reject -- https://master.php.net/note/reject/74716 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125842) next »