-1

I have two dates in Python. One is received from the database:

(datetime.datetime(2017, 10, 10, 10, 10, 10),) 

And the other from the email:

Thu, 18 Jan 2018 15:50:49 -0500. 

I want to compare these two dates in Python for which I think these dates need to be converted in one specific format. How to convert these dates in one specific format to compare?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • Are you perhaps looking for something like this? https://stackoverflow.com/questions/3278999/how-can-i-compare-a-date-and-a-datetime-in-python – Kevin Jan 30 '18 at 06:27

2 Answers2

1

Convert both to datetime (very powerful with dates).

dt_date = datetime.datetime(2017, 10, 10, 10, 10, 10)
str_date = 'Thu, 18 Jan 2018 15:50:49 -0500'

pd.to_datetime([dt_date,str_date])

Output:

DatetimeIndex(['2017-10-10 10:10:10', '2018-01-18 20:50:49']
thomas.mac
  • 1,236
  • 3
  • 17
  • 37
0
from datetime import datetime

start_date = datetime(2017, 10, 10, 10, 10, 10)

email_date = datetime.strptime("Thu, 18 Jan 2018 15:50:49", "%a, %d %b %Y %H:%M:%S")
start_date, email_date
>>>datetime.datetime(2017, 10, 10, 10, 10, 10)   datetime.datetime(2018, 1, 18, 15, 50, 49)
Veera Balla Deva
  • 790
  • 6
  • 19