Jump to content

Archived

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

graecyn

Time Interval Counter -- Is it possible?

Recommended Posts

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 time
Determine what time the last update was made
Based on the current time, and the time the last update was made, calculate how many increments of 25 to add to the counter
Update 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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.