reset a counter every year

I have a counter that I want to
reset the first time anything gets saved
in a new year. But I don't know how
to do it. If anyone can send me some pseudo code or code or an algorithm
or anything I'd be so happy.

I start the counter at zero and the first of january when something gets saved I want it to start at zero again.

thanks!
LVL 3
otroligafreddeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AlexVirochovskyConnect With a Mentor Commented:
otro, sorry, that i reply, but we want
you reaction! what do you think about
our recomendations? It helps or you want something else?
Happy New Year. Alex
0
 
AlexVirochovskyCommented:
Next way i use :
1. test: exist counter (in ini file or
 for Win95/98 in Registry).
2. If Not exists, save 0 to current
   and set yearSaved to current and
   save in same place.
3. By timer test every hour:
   New year? (compare with saved)
   if new, save new year and counter = 0.
4. Happy New Year!
Alex
0
 
rgoughCommented:
#define SECONDS_IN_A_YEAR   31556736 /* 60*60*24*365.24 */

/* persistent variables - need to stored to non-volatile memory
 * if your program doesn't run constantly.  
 * good idea even if it is supposed to run constantly
 */
BOOL saved_this_year = FALSE;
time_t this_year = 0;


/* in the code where you do a save */

time_t current_year = time() / SECONDS_IN_A_YEAR;

if (current_year > this_year) {
   saved_this_year = FALSE;
}

if (!saved_this_year) {
   saved_this_year = TRUE;
   this_year = current_year;
   /* reset your counter here */
}
0
 
inprasCommented:
Can U explain more what difficulty UR facing?
Regards
0
 
AlexVirochovskyCommented:
otro..., what do you think about
our recomendations?
0
All Courses

From novice to tech pro — start learning today.