note 109850 deleted from function.time by aharvey

From: Date: Tue, 28 Aug 2012 01:33:07 +0000
Subject: note 109850 deleted from function.time by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190241@lists.php.net to get a copy of this message
Note Submitter: itechmv.com ---- This is a very basic and simple function to display either min -OR- hrs and min -OR- days and hrs -OR- days depending on how many seconds are given. This function only tested in wordpress Example use: <?php $td = time_diff($timestamp1-$timestamp2); // has to be a positive result $td .= ($td=="now")? "":" ago"; // in this example "ago" echo $td; function time_diff($s){ $time = get_post_time('G', true, $post); $s = time() - $time; if($s>=1) { $td = "$s sec"; } if($s>59) { $m = (int)($s/60); $s = $s-($m*60); // sec left over $td = "$m min"; if($s>1) $td .="s"; } if($m>59){ $hr = (int)($m/60); $m = $m-($hr*60); // min left over $td = "$hr hr"; if($hr>1) $td .= "s"; if($m>0) $td .= ", $m min"; } if($hr>23){ $d = (int)($hr/24); $hr = $hr-($d*24); // hr left over $td = "$d day"; if($d>1) $td .= "s"; if($d<3){ if($hr>0) $td .= ", $hr hr"; if($hr>1) $td .= "s"; } } return $td; } ?>

« previous php.notes (#190241) next »