0

what is right method of finding sting date difference in python

Date format is "2020-11-16 12:34:21".

I written below code which is working as expecting and I tested with multiple examples.

However I am still not confident this is the way we should implement or any bugs in code. If somebody review and help me this the correct method will be helpful

code:

strdate1="2020-11-16 12:34:21"
dt_tuple1=tuple([int(x) for x in strdate1[:10].split('-')])+tuple([int(x) for x in strdate1[11:].split(':')])

strdate2="2020-11-16 12:34:20"
dt_tuple2=tuple([int(x) for x in strdate2[:10].split('-')])+tuple([int(x) for x in strdate2[11:].split(':')])

if dt_tuple1 == dt_tuple2:
    print("No changes in time")

if dt_tuple1 > dt_tuple2:
    print("time-1 is latest")

if dt_tuple1 < dt_tuple2:
    print("time-2 is latest")
Vidya
  • 335
  • 6
  • 17

0 Answers0