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
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
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.

ty sir

 

quick fix

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.