Jump to content

Time ago function always referring to January 1st 1970


defroster

Recommended Posts

Hello,

 

When I use this function, the time always refers to January 1st 1970 ?! How come?

I get the output '4 decades 1 year 11 months' regardless of which date I enter into the function.. ?

 

function timeAgo($tm,$rcs = 2) {
    $cur_tm = time(); $dif = $cur_tm-$tm;
    $pds = array('second','minute','hour','day','week','month','year','decade');
    $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
    for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);

    $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
    if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs);
    return $x;
}

 

When I call for the function I use this:

timeAgo($row['dateposted'])

 

The format in the database for 'dateposted' is:

2006-08-14 23:29:23

 

Any ideas what I am doing wrong? Thanks a million

The function appears to be expecting a unix timestamp value, but your providing it something else.  You need to convert the value from your database into a timestamp prior to passing it to the function.  strtotime will probably work.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.