How can I compare a date and a datetime in Python?

后端 未结 5 1281
野趣味
野趣味 2020-12-01 03:12

Here\'s a little snippet that I\'m trying execute:

>>> from datetime import *
>>> item_date = datetime.strptime(\'7/16/10\', \"%m/%d/%y\")
         


        
5条回答
  •  温柔的废话
    2020-12-01 04:12

    I am trying to compare date which are in string format like '20110930'

    benchMark = datetime.datetime.strptime('20110701', "%Y%m%d") 
    
    actualDate = datetime.datetime.strptime('20110930', "%Y%m%d")
    
    if actualDate.date() < benchMark.date():
        print True
    

提交回复
热议问题