'how to crate a list of days from x date till y date by adding 7 days?
I have tried this code but showing nothing while checking the list length
from datetime import date
from datetime import timedelta
sdate= date(1990,10,25)
tdate=date(1990,10,25)
i=7
rqd_dt=[]
adate = date(2022,12,31)
while adate > tdate:
rqd_dt.append(tdate)
tdate = sdate+timedelta(days=i)
print(len(rqd_dt))
Solution 1:[1]
You have a small mistake only. Change this line:
tdate = sdate+timedelta(days=i)
to
tdate = tdate+timedelta(days=i)
This way, tdate keeps incrementing by 7 days. As you had it, tdate remains the same every loop, so it's not stuck at the print statement - it's stuck in an infinite loop. If you added a little investigative print statement inside your while loop, you would see this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | blarg |
