Я пытаюсь распечатать дневные диапазоны с сегодняшнего дня до года назад. Так что я могу применить это к sql-запросу в другом моем коде.
Я знаю, что мой алгоритм работает, но мне нужно вычесть 1 день из формата '2014-05-15' Вот код
from datetime import date, timedelta
import datetime
current_date = datetime.date.today()
datecounter = 0
while datecounter != 365:
print current_date
date_start = current_date
print date_start
# current_date = current_date.timedelta(days=1)
print current_date
print 'the date is between', date_start, 'and', current_date
datecounter += 1
Я ищу этот код для вывода
the date is between 2014-05-16 and 2014-05-15
the date is between 2014-05-15 and 2014-04-14
и т.д
Я написал надуманный пример, основанный на логике, если вы хотите запустить его самостоятельно, вы можете лучше понять, что я пытаюсь сделать.
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
curdate = 5
for i in x:
print curdate
date_start = curdate
curdate = curdate - 1
# print curdate
print ' the date is between', date_start, 'and', curdate
print ' ---------- '