Jump to content


Photo

Time Interval Counter -- Is it possible?


  • Please log in to reply
2 replies to this topic

#1 graecyn

graecyn
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationWashington, DC

Posted 07 March 2006 - 02:06 PM

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!
"I am always doing that which I cannot do, so that I may learn how to do it." -- Pablo Picasso

www.graecyn.com | www.beautifulgeek.com

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 02:26 PM

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:
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";

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 graecyn

graecyn
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationWashington, DC

Posted 07 March 2006 - 02:35 PM

Beautiful!

Thanks a ton. :) Works beautifully.
"I am always doing that which I cannot do, so that I may learn how to do it." -- Pablo Picasso

www.graecyn.com | www.beautifulgeek.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users