python从时间段中选择一天_在python中,如何从datetime格式中减去一天?

我试着打印从今天到一年前的日期范围。因此,我可以将此应用于其他代码中的sql查询。

我知道我的算法有效,但我需要从格式“2014-05-15”中减去1天

这是密码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 ' ---------- '

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值