开发者

Workweek start and end date

I need to write a script that gives me a range of days from today back to the beginning of the work week. In other words, say that today is Tuesday August 9th and I click on my button I should get two dates, a start date equals to "8/7/2011" and end date equals to today or "8/9开发者_高级运维/2011" I already got the code to give me a week prior to today like:

startDate = System.DateTime.Now.Subtract(System.TimeSpan(7, 0, 0, 0))
endDate   = System.DateTime.Now

I just don't know how to make it get the current week and subtract from there.

Thanks!


I am not sure whether my code helps you or not but you can try the following sample:

from System import DateTime, TimeSpan, DayOfWeek

endDate = DateTime.Now
startDate = DateTime.Now
span = TimeSpan()
daySpan = span.FromDays(1)

while startDate.DayOfWeek != DayOfWeek.Monday:
    startDate -= daySpan

print startDate, endDate

Think it could be done the easier way as well as using standard python datetime module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜