Version: 1.0
Type: Function
Category: Calendars/Dates
License: GNU General Public License
Description: This function returns, for a given number of seconds how long ago it happened. For example: echo “this message was posted “.timetext(1036148464).” ago”; would say something like ‘ this message was posted, one month, 2 days, 14 hours and 10 minutes ago’
Have fun!
<?php function timetext($seconds){ $day=date("j",$seconds)-1; $month=date("n",$seconds)-1; $year=date("Y",$seconds)-1970; $hour=date("G",$seconds)-1; $minute=(int) date("i",$seconds); $returnvalue=false; if($year){ if($year==1) $return[]="one year"; else $return[]="$year years"; } if($month){ if($month==1) $return[]="one month"; else $return[]="$month months"; } if($day){ if($day==1) $return[]="a day"; else $return[]="$day days"; } if($hour){ if($hour==1) $return[]="one hour"; else $return[]="$hour hours"; } if($minute&&$minute!=00){ //if($minute==45){ // $return[]="drie kwartier"; //}else if($minute==30){ $return[]="half an hour"; //}elseif($minute==15){ //$return[]="een kwartier"; }elseif($minute==1){ $return[]="a minute"; }else{ $return[]="$minute minutes"; } } for($i=0;$i<count($return);$i++){ if(!$returnvalue){ $returnvalue=$return[$i]; }elseif($i<count($return)-1){ $returnvalue.= ", ".$return[$i]; }else{ $returnvalue.= " and ".$return[$i]; } } return $returnvalue; } ?>