-2

I have a function where I read the time from a file. I put this into a variable. I then subtract this value from the current time which most of the time will give me a value around .

My problem is im not sure how to check if this value which I attach to a variable is greater than say 20 seconds.

def numberchecker():
    with open('timelog.txt', 'r') as myfile:
        data=myfile.read().replace('\n','')

    a = datetime.strptime(data,'%Y-%m-%d %H:%M:%S.%f')
    b = datetime.now()
    c = b-a   (This outputs for example: 0:00:16.657538)

    d = (would like this to a number I set for example 25 seconds)


    if c > d:
        print ("blah blah")
user401708
  • 23
  • 1
  • 6

2 Answers2

0

The difference which you're getting is a timedelta object.

You can just use c.seconds to get the seconds.

DM_Morpheus
  • 710
  • 2
  • 7
  • 20
-1
if c.total_seconds() > datetime.timedelta(seconds=d):
    print ("blah blah")
Fraser
  • 91
  • 8