Hey guys, I got bored so I made a function that replaces your Epoch (UNIX) timestamp with an actual string that makes sense for humans.
PHP Code:
<?php
/*****************
* human_time (c) Scott Kaye
* usage: pass human_time an Epoch timestamp, and it will return a nicer value, such as '4 minutes ago' or '8 seconds ago'
*****************/
$sample=1316991051; //Sample Epoch time to test it out!
function human_time($t){
$cT=time();
if(date('Y',$cT)==date('Y',$t)){
$o='Some time this year';
if(date('n',$cT)==date('n',$t)){
$o='This month';
if(date('W',$cT)==date('W',$t)){
$o='This week';
if(date('j',$cT)==date('j',$t)){
$o='Today';
if(date('g',$cT)==date('g',$t)){
$o='Less than an hour ago';
if(date('i',$cT)==date('i',$t)){
$a=date('s',$cT)-date('s',$t);
$p=($a>1)?"s":null;
$o=$a." second{$p} ago";
}
else {
$a=date('i',$cT)-date('i',$t);
$p=($a>1)?"s":null;
$o=$a." minute{$p} ago";
}
}
else {
$a=date('g',$cT)-date('g',$t);
$p=($a>1)?"s":null;
$o=$a." hour{$p} ago";
}
}
else {
$a=date('j',$cT)-date('j',$t);
$p=($a>1)?"s":null;
$o=$a." day{$p} ago";
}
}
else {
$a=date('W',$cT)-date('W',$t);
$p=($a>1)?"s":null;
$o=$a." week{$p} ago";
}
}
else {
$a=date('n',$cT)-date('n',$t);
$p=($a>1)?"s":null;
$o=$a." month{$p} ago";
}
}
else {
$a=date('Y',$cT)-date('Y',$t);
$p=($a>1)?"s":null;
$o=$a." year{$p} ago";
}
return $o;
}
echo human_time($sample);
?>
It's probably full of bugs, but meh. Took me 5 minutes (copy-paste, copy-paste, copy-paste...).
As always, though, if you do find anything wrong with it, please let me know and I'll attempt to fix it!
EDIT: OMG, my 666th post. Oh, dis is bad! (TF2 reference)