can't compare datetime.datetime to datetime.date

前端 未结 6 2027
野趣味
野趣味 2020-12-05 12:20

I have the following code and am getting the above error. Since I\'m new to python I\'m having trouble understanding the syntax here and how I can fix the error:

<         


        
6条回答
  •  离开以前
    2020-12-05 13:22

    You can use the datetime.datetime.combine method to compare the date object to datetime object, then compare the converted object with the other datetime object.

    import datetime
    
    dt1 = datetime.datetime(2011, 03, 03, 11, 12)
    day = datetime.date(2011, 03, 02)
    dt2 = datetime.datetime.combine(day, datetime.time(0, 0))
    
    print dt1 > dt2
    

提交回复
热议问题