bisht
bisht

Reputation: 59

How I can calculate the duration between these two times '9:38 AM - 4 Mar 2015' and '10:06 AM - 26 Feb 2015' in Python

I have a json file where I have publistime as one entry and I want to find the difference between to time. "pubTime": "9:38 AM - 4 Mar 2015" "pubTime": "12:52 AM - 4 Mar 2015", pubTime": "5:03 PM - 3 Mar 2015",

Upvotes: 1

Views: 24

Answers (1)

bisht
bisht

Reputation: 59

Thanks. Got it:

from datetime import datetime

date_1 = datetime.strptime('10:06 AM - 26 Feb 2015', '%I:%M %p - %d %b %Y')

date_2 = datetime.strptime('9:38 AM - 4 Mar 2015', '%I:%M %p - %d %b %Y')

diff = date_2 - date_1

print(diff)

Upvotes: 1

Related Questions