无法将 datetime.datetime 与 datetime.date 进行比较

无法将 datetime.datetime 与 datetime.date 进行比较

问题描述:

我有以下代码,但出现上述错误.由于我是 Python 新手,因此无法理解此处的语法以及如何修复错误:

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:

if not start or date < start: start = date

有一个 datetime.date() 方法可以将日期时间转换为日期.

There is a datetime.date() method for converting from a datetime to a date.

做相反的转换,你可以使用这个函数datetime.datetime(d.year, d.month, d.day)

To do the opposite conversion, you could use this function datetime.datetime(d.year, d.month, d.day)