python get tommorows date dd.mm.yy problem

时间:2018-11-05 17:43:39

标签: python date

So basically I want to check if a certain string includes tommorows date so i made this date variable (see code). Now the problem is every month on the last day this is going to be wrong. For example the 30th of september, with the way i did it, its going to say that tommorow will be the 31 of september, wich does not exist however. I need it to say that tommorow is the 1. of october. Any suggestions? It has to be in the format dd.mm.yy please.

  day = str(datetime.datetime.today().day+1)
  month = str(datetime.datetime.today().month)
  year = str(datetime.datetime.today().year)      
  date = day + "." + month + "." + year

2 个答案:

答案 0 :(得分:3)

今天只增加一天

tomorrow = datetime.datetime.today() + datetime.timedelta(days=1)
print(str(tomorrow),tomorrow.strftime("%d.%m.%y"))

答案 1 :(得分:0)

relativedelta也可以使用

import datetime
from dateutil.relativedelta import relativedelta 
tomorrow = datetime.datetime.today() + relativedelta(days=1)
print(str(tomorrow),tomorrow.strftime("%d.%m.%y"))
相关问题