目标:
问题:
问题:
代码
from datetime import date
from datetime import time
from datetime import datetime
dateTimeStart = "2014-01-01 12:00:00"
def main():
dateTime1 = datetime.strptime(dateTimeStart, "%Y-%m-%d")
today = date.today()
if dateTime1 > "today":
print "No"
if __name__ == "__main__":
main();
答案 0 :(得分:7)
您还需要解析时间部分:
datetime.strptime(dateTimeStart, "%Y-%m-%d %H:%M:%S")
然后你可以像这样比较你的日期:
if dateTime1.date() > date.today():
print "No"
date()
函数返回datetime
对象的日期。