Function TimeAgo

432
.
jimy
Just a simple code
step by step
#1. take some coffe and snack
#2. pray
#3. then go to sleep..

now serious open
Root/system/johncms/Tools.php

add this
/*Mod Time Ago, By: jimy ironyzm*/
	public function TimeAgo($var){
		$m = time()-$var; $times='just now';
		$t = array('year'=>31556926,'month'=>2629744,'week'=>604800,'day'=>86400,'hour'=>3600,'min'=>60,'sec'=>1);
		foreach($t as $u=>$s){
			if($s<=$m){
				$v=floor($m/$s); $times="$v $u".($v==1?'':'').' ago.';
				break;
			}
		}
		return $times;
	}


how to use :
example :
echo $tools->TimeAgo($query['time']);

explain : $query = your query e.g $res['time']
Прикрепленные файлы:
.
btw I put that code before public function displayError
Прикрепленные файлы:
.
example usage
Прикрепленные файлы:
Всего: 3