使用python得到最后的日期? [英] get lastweek dates using python?

查看:122
本文介绍了使用python得到最后的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用python来得到最后一周的日期。



如果日期是:2014年10月10日意味着



应该打印

  2014年10月10日,2014年10月10日,2014年10月08日,2014年10月7日,2014年10月06日,2014年10月05日,04年04月04日
 今天,c $ c> 

=(10 OCT 2014)

dates = [today + datetime.timedelta(days = i)for i in range(-4 - today.weekday(),4 - today.weekday())]
打印日期

我收到此错误:

  exceptions.AttributeError:'unicode'对象没有属性'weekday'


解决方案

您的问题和算法似乎没有对应。这是你以后吗?

  from datetime import date 
from datetime import timedelta
today =日期(2014,10,10)#或您可以在今天= date.today()为今天的日期

为我在范围(0,7):
打印今天 - timedelta days = i)


I am trying to get the date of the last week with python.

if date is : 10 OCT 2014 means

It should be print

10 OCT 2014, 09 OCT 2014, 08 OCT 2014, 07 OCT 2014, 06 OCT 2014, 05 OCT 2014, 04 OCT 2014

I tried:

today = (10 OCT 2014)

dates = [today + datetime.timedelta(days=i) for i in range(-4 - today.weekday(), 4 - today.weekday())]
print dates

I am getting this error:

exceptions.AttributeError: 'unicode' object has no attribute 'weekday'

解决方案

Your question and algorithm don't seem to correspond. Is this what you're after?

from datetime import date
from datetime import timedelta
today = date(2014, 10, 10) # or you can do today = date.today() for today's date

for i in range(0,7):
    print today - timedelta(days=i)

这篇关于使用python得到最后的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆