I am developing an application in python where I need to calculate time elapsed and take appropriate action. I have two times as by default provided and current. I want compare the difference with some other time which is provided in string format.
I have tried following:
d1 = datetime.datetime(2015, 1, 21, 9, 54, 54, 340000)
print d1
d2 = datetime.datetime.now()
print d2
print d2 - d1
d3 =datetime.datetime.strptime("22:17:46.476000","%H:%M:%S.%f")
print d3
Output of the above program is :
2015-01-21 09:54:54.340000
2015-01-21 22:28:45.070000
12:33:50.730000
1900-01-01 22:17:46.476000
Here time difference is' 12:33:50.730000' and I want to compare it with '22:17:46.476000' which is string.
As I tried to convert string '22:17:46.476000' to time I got year as 1990. I want only time as '22:17:46.476000'. So I can compare these two time using timedelta.
How to get rid of year 1990-01-01. I want only '22:17:46.476000'.
I tried using time as time.strptime("22:17:46.476000","%H:%M:%S.%f")
but it give output as time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=22, tm_min=17, tm_sec=46, tm_wday=0, tm_yday=1, tm_isdst=-1)
Thanks