calendar by week

G

GuineaPig

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
 
G

GuineaPig

Peter said:
GuineaPig wrote:




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:



... 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
 
P

Peter Otten

GuineaPig said:
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:
.... print d
....
2003-12-29
2003-12-30
2003-12-31
2004-01-01
2004-01-02
2004-01-03
2004-01-04

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,353
Members
48,041
Latest member
Oliwen826

Latest Threads

Top