Jump to content

date issue again :(


Monkuar

Recommended Posts

function timeAgo($tm,$rcs = 1) {
    $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 .= $this->timeAgo($_tm, --$rcs);
    return $x;
}

 

This is my function

 

I use it alot

 

My code:

$endtime = $std->timeAgo($lotto['start_time']+3600);

$lotto['start_time'] = 1327482941

 

+3600 is 1 Hour correct?

But this displays:

 

Next Drawing in: -3219 seconds

 

each refresh it goes down 3218/etc which is GOOD! But why is it using the minus sign and not going through the function properly?

 

Link to comment
https://forums.phpfreaks.com/topic/255732-date-issue-again/
Share on other sites

Try chaning $dif = $cur_tm-$tm; to $dif = $tm - $cur_tm;.

 

I'm going to take a wild guess and say that the reason you're getting -32xx is because you're subtracting a larger number (future time) from a smaller number (current time). Switching the variables around, you should get a positive result. If not, I dunno.

Link to comment
https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310973
Share on other sites

  Quote

Try chaning $dif = $cur_tm-$tm; to $dif = $tm - $cur_tm;.

 

I'm going to take a wild guess and say that the reason you're getting -32xx is because you're subtracting a larger number (future time) from a smaller number (current time). Switching the variables around, you should get a positive result. If not, I dunno.

ty sir

 

quick fix

Link to comment
https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310985
Share on other sites

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.