0

I have two different values. One value(A) is 2020-03-06T10:00:00+05:30 and another one(B) is 2020-03-03 14:04:02. These two are in str formats. Now I have to compare these two different values as date.If the 'A' is greater than 'B' I have return 'True'

The method I have tired is

if A>B:
return True
else:
return False

What is happening is if it's greater or smaller it's always going to if statement only. I am getting A & B from differnet sources and it's in the same format which I have given above.

  • 1
    Maybe convert them to datetime objects first? – Chris Mar 03 '20 at 14:18
  • 1
    Why don't you just convert them to datetimes rather than rely on lexicographical ordering? – roganjosh Mar 03 '20 at 14:19
  • Both are in different formats,so I am not sure how to convert it. I tried datetime.datetime.strptime(date,'%Y-%m-%dT%H:%M:%S+05:30').But that's not working –  Mar 03 '20 at 14:23
  • 2
    So convert them with two different format strings. I don't see how it's a barrier that they are in different formats – roganjosh Mar 03 '20 at 14:26

0 Answers0