[英]How to compare date in python? I have a month date year format and want to compare to the current date (within 7 days)
[英]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'
出局:
您無法選擇上一個日期
我希望我的回答很有幫助。 如果有任何疑問請評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.