note 106097 deleted from function.date by tularis

From: Date: Thu, 09 Feb 2012 20:48:56 +0000
Subject: note 106097 deleted from function.date by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185948@lists.php.net to get a copy of this message
Note Submitter: alexander at acmbdesign dot com ---- A smaller "time since incident" example that takes a datetime string as input : <?php function timesince( $tsmp ) { $diffu = array( 'seconds'=>2, 'minutes' => 120, 'hours' => 7200, 'days' => 172800, 'months' => 5259487, 'years' => 63113851 ); $diff = time() - strtotime($tsmp); $dt = '0 seconds ago'; foreach($diffu as $u => $n){ if($diff>$n) {$dt = floor($diff/(.5*$n)).' '.$u.' ago';} } return $dt; } ?> // example output: 10 seconds ago / 90 minutes ago / 16 months ago / 3 years ago

« previous php.notes (#185948) next »