Python Forum

Full Version: Reset counter when the day turns over
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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?
(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%
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