0

I have two dates I am comparing.

a = datetime.datetime.strptime('2019-03-09','12:09 AM')
b = datetime.datetime.strptime('2019-03-09','11:56 PM')
a = 2019-03-09 12:09 
b = 2019-03-09 11:56 
if a > b:
    print('yes')

What's happening is a is greater than b. But it shouldn't be. It seems like its cutting off the am and pm.

1 Answer 1

2

You aren't using that strptime function correctly, it should be like this:

a = datetime.datetime.strptime('2019-03-09 12:09 AM','%Y-%m-%d %I:%M %p')
b = datetime.datetime.strptime('2019-03-09 11:56 PM','%Y-%m-%d %I:%M %p')

if a > b:
    print('yes')

And then, you're overwriting a and b anyway.

Here is the doc for how to use strptime

Sign up to request clarification or add additional context in comments.

1 Comment

I just spotted my error. Thanks I will upvote and accept your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.