1

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",

bisht
  • 59
  • 7
  • 2
    Possible duplicate of [How do I calculate number of days between two dates using Python?](https://stackoverflow.com/questions/151199/how-do-i-calculate-number-of-days-between-two-dates-using-python) – Shashwat Mar 09 '18 at 06:07
  • The format is different so I am facing problem in doing the calculation. I am little new to Python – bisht Mar 09 '18 at 17:17

1 Answers1

1

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)

bisht
  • 59
  • 7