Jump to content

Time Interval Counter -- Is it possible?


graecyn

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!
Link to comment
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
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.