current week / weeks in year - best practice

Aljosa Mohorovic aljosa.mohorovic at
Thu Jul 31 18:11:48 CEST 2008

On Jul 31, 5:42 pm, Aljosa Mohorovic <aljosa.mohoro... at>
> 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
last_day = first_day + timedelta(days=6)

any comments on this?

Aljosa Mohorovic

More information about the Python-list mailing list