- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
function date_to_text($date){
$now=time();
if ($s=strtotime($date)) //the function returns false is $date is not a string (as already in numeric unix date format)
$date = $s;
$d=round(($now-$date)); //s
//echo $d;
if($d>60){
$d=$d/60;//m
if($d>60){
$d=$d/60;//h
if($d>24){
$d=$d/24;//d
if($d>7){
$d=$d/7;//w
if($d>(52/12)){
$d=$d/52*12;//m
if($d>12){
$d=$d/12;//y
$d=floor($d);
$str=$d.' year'.(($d>1)?'s':'');
}else{
$d=floor($d);
$str=$d.' month'.(($d>1)?'s':'');
}
}else{
$d=floor($d);
$str=$d.' wk'.($d>1?'s':'');
}
}else{
$d=floor($d);
$str=$d.' day'.($d>1?'s':'');
}
}else{
$d=floor($d);
$str=$d.' hr'.(($d>1)?'s':'');
}
}else{
$d=floor($d);
$str=$d.' min'.(($d>1)?'s':'');
}
}elseif ($d>0) {
$d=floor($d);
$str=$d.' sec'.(($d>1)?'s':'');
}
if ($d>0){
$str.=' ago';
} else {
$str = '';
}
return $str;
}
Horse2 22.10.2013 14:10 # −7
Horse2 22.10.2013 14:11 # −6
Tairesh 22.10.2013 14:13 # +4