我想将叶子持续时间的日期与 odoo python 中的当前日期进行比较

I want to compare date of duration of leaves with the current date in odoo python

这是我编写并继承自 hr.holidays 的程序 如果所选日期早于当前日期,则应提供错误消息。 代码-

from datetime import date

if self.date_from <= date.today():
            print 'You cannot select the previous date'

但是报错-

TypeError: can't compare datetime.date to bool

谢谢

你好 Ujjwal Singh Baghel,

试试下面的代码,

#!/usr/bin/python
import datetime
i = datetime.datetime.now()

print ("Current date & time = %s" % i)


if self.date_from <= str(i):
            print 'You cannot select the previous date'

from datetime import date
if self.date_from <= str(date.today()):
            print 'You cannot select the previous date'

例如

from datetime import date
if "10/07/2017" <= str(date.today()):
            print 'You cannot select the previous date'

输出:

You cannot select the previous date

希望我的回答对您有所帮助。 如有任何疑问请留言。