current week / weeks in year - best practice

Aljosa Mohorovic aljosa.mohorovic at gmail.com
Thu Jul 31 12:11:48 EDT 2008


On Jul 31, 5:42 pm, Aljosa Mohorovic <aljosa.mohoro... at gmail.com>
wrote:
> what if i know current context week = 20 (example), what would be the
> best way to get datetime objects for first and last day of current
> context week?
> by "current context week" i don't mean current week for current year
> but current week when program is iterating all weeks in year.

if w = current context week and now is current datetime object  this
is how i calculate days:
first_day = datetime.strptime("%s %s" % (now.year, str((w-1)*7)), "%Y
%j")
last_day = first_day + timedelta(days=6)

any comments on this?

Aljosa Mohorovic



More information about the Python-list mailing list