让我们说,我有两个约会。
d1= date(2016,12,01)
d2= date(2017,01,31)
现在从这两个日期开始,我试图打印从d1到d2的所有每周日期,例如:
2016, 12, 01
2016, 12, 08
2016, 12, 15
2016, 12, 22
2016, 12, 29
2017, 01, 05
2017, 01, 12
2017, 01, 19
2017, 02, 26
谢谢。
答案 0 :(得分:2)
import datetime
d1 = datetime.date(2016,12,01)
d2 = datetime.date(2017,01,31)
weekly = d1
while weekly <= d2:
print weekly
weekly = weekly + datetime.timedelta(days=7)