2018 up to now | 2017 | 2016 | 2015 | 2014 | 2013 | 2012 | 2011 | 2010 | 2009 | 2008 | 2007

(older archive entries before 2007 are not shown here, but included in the onsite-search)

Mailing List - Entries of 2014


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [QF-Test] need Sunday of the current week (please help)


  • Subject: Re: [QF-Test] need Sunday of the current week (please help)
  • From: Michael Pruemm <eso@?.org>
  • Date: Tue, 02 Dec 2014 09:46:51 +0100

On 12/02/2014 12:52 AM, Yi Li wrote:
I’m trying to come up with a script that needs end date for the current
week (i.e Sunday).

Can someone help me please?

Here is a copy from my Jython terminal:

>>> from datetime import date, timedelta
>>> today = date.today()
>>> days_until_sunday = 6 - today.weekday()
>>> sunday = today + timedelta(days_until_sunday)
>>>
>>> today
datetime.date(2014, 12, 2)
>>> today.weekday()
1
>>> days_until_sunday
5
>>> sunday
datetime.date(2014, 12, 7)

The weekday is 0 for Monday and 6 for Sunday. If you run this on a
Sunday, both "today" and "sunday" will be the same day.

Hope that helps,

- Michael