无法将 datetime.datetime 与 datetime.date 进行比较 [英] can't compare datetime.datetime to datetime.date

查看:78
本文介绍了无法将 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)

这篇关于无法将 datetime.datetime 与 datetime.date 进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆