Python Forum
Reset counter when the day turns over
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reset counter when the day turns over
#1
I want to monitor an event's and store value in counter and when the day turns over, it resets the counter to zero.

Here is a example
Day: 28 Count: 0
Day: 28 Count: 1
Day: 28 Count: 2
... .....
Day: 28 Count: 123

Day: 29 Count: 0
Day: 29 Count: 1
Day: 29 Count: 2
Day: 29 Count: 3
... ... ...
Day: 29 Count: 565

Day: 30 Count: 0
Day: 26 Count: 1

Day 28 have 123 entries because the next day 29 started after the 28 turned over.

Day 29 have 565 entries because the next day 30 started after the 29 turned over.

any idea how to make script

import time
import datetime
count = 0 
now = datetime.datetime.now()
Reply
#2
So you want a script that's always running?
What happens if the machine loses power? Would you expect the count to be 0 once it started back up, or to pick up where it left off?
What's your margin of error?
Reply
#3
(Dec-28-2018, 06:02 PM)nilamo Wrote: So you want a script that's always running?
yes

Quote:What happens if the machine loses power? Would you expect the count to be 0 once it started back up, or to pick up where it left off?
if the power loss start count from 0
Quote:What's your margin of error?
error should be less then 5%
Reply
#4
Ok, then I guess keep track of what day it was the last time you incremented, and if it's different, reset the counter? datetime.date.today().day would be what day of the month it is. https://docs.python.org/3/library/dateti...date.today
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a sequential number (counter) and reset at each duplicate Mekala 0 1,738 Sep-20-2020, 05:02 AM
Last Post: Mekala
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,757 Jun-18-2020, 04:59 PM
Last Post: QTPi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020