Forum Moderators: coopster

Message Too Old, No Replies

Help with a php function

         

nfs2

2:33 am on Apr 3, 2006 (gmt 0)

10+ Year Member



This is somewhat related to my last post, but its about something sppecific so i figured id make a new thread.

The following function is supposed to return how long ago the entered time was. For example, if i enter march 2, it should say 1 month ago.

Anyways, when i enter the current unix timestamp, it tells me it was 36 years ago.

Here's the function

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;
}

Now, the unix timestamp is 10 digits long, but the example i found for this function is only 7.. What kind of timestamp is only 7 digits long?

Anyways, does anyone know how to use this code? There's zero information online about it.

coopster

12:30 am on Apr 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



UNIX timestamps are returned using the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). 2006 - 1970 is 36 years lapsed.

nfs2

3:56 am on Apr 6, 2006 (gmt 0)

10+ Year Member



Thanks, i figured out that i had to subtract the timestamp from the current timestamp, then pass the result through the function.