graecyn Posted March 7, 2006 Share Posted March 7, 2006 Hi everyone. It's me again.Here's my dilemma:I need a time interval counter. For instance, let's say I have a simple text counter starting at 0. Every 15 minutes, I want to add say 25 to that number.So at 15 minutes, the counter will go from 0 to 25, at 30 the counter will go from 25 to 50, and so on.I imagine what I will need to do is:Find the current timeDetermine what time the last update was madeBased on the current time, and the time the last update was made, calculate how many increments of 25 to add to the counterUpdate the counter to display the calculated number.Now, I have no idea where to look or even how to begin doing this...Any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/4329-time-interval-counter-is-it-possible/ Share on other sites More sharing options...
obsidian Posted March 7, 2006 Share Posted March 7, 2006 i would just set a fixed starting date and calculate the new time/date every time the function is called instead of trying to "update" or store the counter anywere if it's a fixed incrementation like that. just write a timer function that will handle it for you:[code]function get_counter() { // set a fixed starting time $start = strtotime("2006-01-01 00:00:00"); // using Jan 1, 2006 at midnight $now = time(); $diff = abs($start - $now); $mins = 15 * 60; // set 15 minute value $increments = floor($diff / $mins); // find out how many increments there have been return 25 * $increments; // 25 for every 15 minute increment figured}// then, just call the function whenever you want:echo "Counter is at: " . get_counter() . "<br />\n";[/code]hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/4329-time-interval-counter-is-it-possible/#findComment-15068 Share on other sites More sharing options...
graecyn Posted March 7, 2006 Author Share Posted March 7, 2006 Beautiful!Thanks a ton. :) Works beautifully. Quote Link to comment https://forums.phpfreaks.com/topic/4329-time-interval-counter-is-it-possible/#findComment-15071 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.