how to print previous 30 days from a date in python and the same in Tkinter

♀尐吖头ヾ 提交于 2021-02-05 12:22:26

问题


I am using Tkinter to build a Corona Travel History Questionnaire.

The front end has options to select a particular date - " D-Day Cronoa Confirmed". Once the D-day is confirmed, the program is supposed to give fields for entering data on travel history.

I am using tkcalendar module in Python.

Problem: How to print the previous 30 days from a given date in python?

Question: Can we do anything in tkcalendar to print the last 30 days from a selected date in the window itself?


回答1:


Using the datetime module you can find the last thirty days from any given date.

For example, the code:

first_date = datetime.datetime.now() - datetime.timedelta(30)

will give you the start period of this 30-day window. From there you simply need to fill in the gaps.




回答2:


datetime and timedelta are made for this.

from datetime import datetime, timedelta                                                                                                                                                            

start = datetime(2020, 1, 1)                                                                                                                                                                        

for day in range(1, 31): 
   print(start-timedelta(days=day))


来源:https://stackoverflow.com/questions/60876768/how-to-print-previous-30-days-from-a-date-in-python-and-the-same-in-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!