Monkuar Posted January 25, 2012 Share Posted January 25, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/255732-date-issue-again/ Share on other sites More sharing options...
Shadowing Posted January 25, 2012 Share Posted January 25, 2012 just curious what are you using this all for. Quote Link to comment https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310953 Share on other sites More sharing options...
Monkuar Posted January 25, 2012 Author Share Posted January 25, 2012 just curious what are you using this all for. lottery system Quote Link to comment https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310958 Share on other sites More sharing options...
Proletarian Posted January 25, 2012 Share Posted January 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310973 Share on other sites More sharing options...
Monkuar Posted January 25, 2012 Author Share Posted January 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255732-date-issue-again/#findComment-1310985 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.