I need to compare two times in Python.
At first I get the current time:
current_time = time.strftime("%H:%M:%S")
I get another time value from list:
another_time = datetime.strptime(some_list[2],'%H:%M:%S')
I want to get the difference between those two times in minutes.I've tried to do this:
time_now = datetime.strptime(current_time, '%H:%M:%S')
d1 = time.mktime(another_time.timetuple())
d2 = time.mktime(time_now.timetuple())
diff = (d2-d1) / 60
What I get is:
-1206.0333333
When I print out another_time I get:
1900-01-01 21:07:23
and current_time:
1900-01-01 01:01:21
So the difference should be 238 minutes.
Is the problem in the year (where does this year come anyway?)? Or what should I change in my code?