473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

calendar by week

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
2 2809
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
15
by: tigrfire | last post by:
I'm trying to write a program that will display the following output: MONTHLY CALENDAR This program displays a calendar. You need to provide the day of the week on which January 1 falls, and...
2
by: patrick delifer | last post by:
I am binding some data to a calendar control. Since I don't want to return all the Data from the DB, I would like to return only the data for the current view of the calendar. The calendar has...
2
by: bb | last post by:
any way to prevent displaying the previous and next months in the calendar control? i have tried just blanking the text out in the dayrender IsOtherMonth and also dynamically changing the...
2
by: Brenden Bixler | last post by:
Hello. I am using the ASP.NET calendar object and am looking to provide a "weekly view", but not the typical "Outlook" style. Rather, I just want it to render the calendar normally, but only...
0
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
1
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.