By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

calendar by week

P: n/a
Hello gurus,

Does anybody know of a function/module that can help me with the
following problem:

In my app the user can encode the starting and ending hours of his
workdays. The app calculates the time the user worked (per week) and
the user's overtime. The results are exported to an excel-sheet for
printing.

One thing that I would like to accomplish is that the user has to only
give in the weeknumber of the year. The app should then write the dates
in this week to the excel-sheet. I've been looking at the calendar and
time modules but I don't quite see a solution there (maybe there is
though, maybe I'm just too much of a newbie.)

Tnx a lot!

Tom
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
GuineaPig wrote:
One thing that I would like to accomplish is that the user has to only
give in the weeknumber of the year. The app should then write the dates
in this week to the excel-sheet. I've been looking at the calendar and
time modules but I don't quite see a solution there (maybe there is
though, maybe I'm just too much of a newbie.)


import datetime

def daysOfWeek(year, week):
day = datetime.date(year, 2, 1)
year, weekBase, dayBase = day.isocalendar()
day += datetime.timedelta(1 - dayBase + (week - weekBase)*7)
delta = datetime.timedelta(1)
for i in range(6):
yield day
day += delta
yield day

Try it:
from daysofweek import daysOfWeek
for d in daysOfWeek(2004, 1):

.... print d
....
2003-12-29
2003-12-30
2003-12-31
2004-01-01
2004-01-02
2004-01-03
2004-01-04

Peter

Jul 18 '05 #2

P: n/a
Peter Otten wrote:
GuineaPig wrote:

One thing that I would like to accomplish is that the user has to only
give in the weeknumber of the year. The app should then write the dates
in this week to the excel-sheet. I've been looking at the calendar and
time modules but I don't quite see a solution there (maybe there is
though, maybe I'm just too much of a newbie.)

import datetime

def daysOfWeek(year, week):
day = datetime.date(year, 2, 1)
year, weekBase, dayBase = day.isocalendar()
day += datetime.timedelta(1 - dayBase + (week - weekBase)*7)
delta = datetime.timedelta(1)
for i in range(6):
yield day
day += delta
yield day

Try it:

from daysofweek import daysOfWeek
for d in daysOfWeek(2004, 1):


... print d
...
2003-12-29
2003-12-30
2003-12-31
2004-01-01
2004-01-02
2004-01-03
2004-01-04

Peter


Thanks Peter,

This works great!

Tom
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.