python get this week days and last week day maybe help for you
2012-04-28 15:34
573 查看
#!/usr/bin/env python
#encoding=utf-8
import datetime
def get_this_week_days(d=datetime.datetime.now()):
d=d-datetime.timedelta(days=d.isoweekday()-1)
day_begin=datetime.datetime(d.year,d.month,d.day,0,0,0)
day_end=datetime.datetime(d.year,d.month,d.day,23,59,59)
days=[(day_begin+datetime.timedelta(days=i),day_end+datetime.timedelta(days=i)) for i in xrange(0,7)]
print days
return days
def get_last_week_days():
d=datetime.datetime.now()-datetime.timedelta(days=7)
return get_this_week_days(d)
get_last_week_days()
#encoding=utf-8
import datetime
def get_this_week_days(d=datetime.datetime.now()):
d=d-datetime.timedelta(days=d.isoweekday()-1)
day_begin=datetime.datetime(d.year,d.month,d.day,0,0,0)
day_end=datetime.datetime(d.year,d.month,d.day,23,59,59)
days=[(day_begin+datetime.timedelta(days=i),day_end+datetime.timedelta(days=i)) for i in xrange(0,7)]
print days
return days
def get_last_week_days():
d=datetime.datetime.now()-datetime.timedelta(days=7)
return get_this_week_days(d)
get_last_week_days()
相关文章推荐
- How to Get Sql sever 2000 WeekFirstDay and WeekLastDay...
- How to Get Sql sever 2000 WeekFirstDay and WeekLastDay...
- How to Get First and Last Day of a Week in SQL Server
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -
- You are working on a database that must be functioning 24 hours a day, 7 days a week. The database i
- [异常]Support for specifying both a day-of-week AND a day-of-month parameter is no
- How to Get First and Last Day of a Month in SQL Server
- This is a bug I believe, and it took me 2-3 days to figure it out. Please do the following to get it working,
- Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
- ABAP CALL FUNCTION 'DATE_GET_MONTH_LASTDAY' 取每月最后一天 'DATE_GET_WEEK'取周
- 【SQL】How to get First and Last day of a Year – TSQL
- Quickstart for Python/WSGI applications This quickstart will show you how to deploy simple WSGI appl
- 【SQL】How to get First and Last day of a month – TSQL
- hi, do you see this new? hoho~~~i will start...thank you so much for you help!~~^~^~~
- Support for specifying both a day-of-week AND a day-of-month parameter is not implemented
- Science Says This Is How to Make the Perfect First Impression You only get one chance for a first i
- PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_sig" for more de
- 79.You are working on a database that must be functioning 24 hours a day, 7 days a week. The databas