473,714 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong number of weeks in years

Hi,

Following code should give the number of weeks in years 1998-2010 for a
Danish calendar (on a Danish box)

GregorianCalend ar cal = new GregorianCalend ar();
for(int i = 1998; i < 2010; i++)
{
DateTime date = new DateTime(i, 12, 31);
int week= cal.GetWeekOfYe ar(date,
CalendarWeekRul e.FirstFourDayW eek,
DayOfWeek.Monda y);
Debug.WriteLine ( String.Format(" Last week in year {0:0} = {1:0}", date.Year,
week));
}

Last week in year 1998 = 53 - OK
Last week in year 1999 = 52 - OK
Last week in year 2000 = 52 - OK
Last week in year 2001 = 53 - Wrong, only 52
Last week in year 2002 = 53 - Wrong, only 52
Last week in year 2003 = 53 - Wrong, only 52
Last week in year 2004 = 53 - OK
Last week in year 2005 = 52 - OK
Last week in year 2006 = 52 - OK
Last week in year 2007 = 53 - Wrong, only 52
Last week in year 2008 = 53 - Wrong, only 52
Last week in year 2009 = 53 - Wrong, only 52

Does anyone see the same pattern as I, and do anyone know why this happens
??

Kind regards, and thanx in advance...

Soren
Nov 16 '05 #1
3 5477
I got the same result on a Swedish box and I used the beta to compile it
with.
---
Microsoft (R) Visual C# .NET Compiler version 8.00.40607.42
for Microsoft (R) Windows (R) .NET Framework version 2.0.40607
Copyright (C) Microsoft Corporation 2001-2003. All rights reserved.
---

Regards
Tony Schon

Soren Jorgensen wrote:
Hi,

Following code should give the number of weeks in years 1998-2010 for a
Danish calendar (on a Danish box)

GregorianCalend ar cal = new GregorianCalend ar();
for(int i = 1998; i < 2010; i++)
{
DateTime date = new DateTime(i, 12, 31);
int week= cal.GetWeekOfYe ar(date,
CalendarWeekRul e.FirstFourDayW eek,
DayOfWeek.Monda y);
Debug.WriteLine ( String.Format(" Last week in year {0:0} = {1:0}", date.Year,
week));
}

Last week in year 1998 = 53 - OK
Last week in year 1999 = 52 - OK
Last week in year 2000 = 52 - OK
Last week in year 2001 = 53 - Wrong, only 52
Last week in year 2002 = 53 - Wrong, only 52
Last week in year 2003 = 53 - Wrong, only 52
Last week in year 2004 = 53 - OK
Last week in year 2005 = 52 - OK
Last week in year 2006 = 52 - OK
Last week in year 2007 = 53 - Wrong, only 52
Last week in year 2008 = 53 - Wrong, only 52
Last week in year 2009 = 53 - Wrong, only 52

Does anyone see the same pattern as I, and do anyone know why this happens
??

Kind regards, and thanx in advance...

Soren

Nov 16 '05 #2
Soren Jorgensen wrote:
Hi,

Following code should give the number of weeks in years 1998-2010 for
a Danish calendar (on a Danish box)

GregorianCalend ar cal = new GregorianCalend ar();
for(int i = 1998; i < 2010; i++)
{
DateTime date = new DateTime(i, 12, 31);
int week= cal.GetWeekOfYe ar(date,
CalendarWeekRul e.FirstFourDayW eek,
DayOfWeek.Monda y);
Debug.WriteLine ( String.Format(" Last week in year {0:0} = {1:0}",
date.Year, week));
}

Last week in year 1998 = 53 - OK
Last week in year 1999 = 52 - OK
Last week in year 2000 = 52 - OK
Last week in year 2001 = 53 - Wrong, only 52
Last week in year 2002 = 53 - Wrong, only 52
Last week in year 2003 = 53 - Wrong, only 52
Last week in year 2004 = 53 - OK
Last week in year 2005 = 52 - OK
Last week in year 2006 = 52 - OK
Last week in year 2007 = 53 - Wrong, only 52
Last week in year 2008 = 53 - Wrong, only 52
Last week in year 2009 = 53 - Wrong, only 52

Does anyone see the same pattern as I, and do anyone know why this
happens ??

Kind regards, and thanx in advance...

Soren


When I look up the weeknumbers in my calendar (dutch, same rules as you used),
dec 31, 2004 is reported as week 1 (of 2004).
Week 52 of 2003 ends on sunday dec 28, so a result of 53 for dec 31 can be
explained (but is still wrong).

Maybe you need to change your algorithm: is dec 31 a monday through wednesday,
then look a week earier for the last "legal" weeknumber.

Hans Kesting

Nov 16 '05 #3
Hans Kesting wrote:
Soren Jorgensen wrote:
Hi,

Following code should give the number of weeks in years 1998-2010 for
a Danish calendar (on a Danish box)

GregorianCalend ar cal = new GregorianCalend ar();
for(int i = 1998; i < 2010; i++)
{
DateTime date = new DateTime(i, 12, 31);
int week= cal.GetWeekOfYe ar(date,
CalendarWeekRul e.FirstFourDayW eek,
DayOfWeek.Monda y);
Debug.WriteLine ( String.Format(" Last week in year {0:0} = {1:0}",
date.Year, week));
}

Last week in year 1998 = 53 - OK
Last week in year 1999 = 52 - OK
Last week in year 2000 = 52 - OK
Last week in year 2001 = 53 - Wrong, only 52
Last week in year 2002 = 53 - Wrong, only 52
Last week in year 2003 = 53 - Wrong, only 52
Last week in year 2004 = 53 - OK
Last week in year 2005 = 52 - OK
Last week in year 2006 = 52 - OK
Last week in year 2007 = 53 - Wrong, only 52
Last week in year 2008 = 53 - Wrong, only 52
Last week in year 2009 = 53 - Wrong, only 52

Does anyone see the same pattern as I, and do anyone know why this
happens ??

Kind regards, and thanx in advance...

Soren
When I look up the weeknumbers in my calendar (dutch, same rules as
you used), dec 31, 2004 is reported as week 1 (of 2004).


sorry, typo: of course that should have been "dec 31, 2003" that is in week 1 of 2004
Week 52 of 2003 ends on sunday dec 28, so a result of 53 for dec 31
can be explained (but is still wrong).

Maybe you need to change your algorithm: is dec 31 a monday through
wednesday, then look a week earier for the last "legal" weeknumber.

Hans Kesting

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11339
by: Stig Andersen | last post by:
Hi does anyone know how to make MS SQL server 2000 calculate the right week number around new year ? According to the help file, MSSQL should follow ISO8601, which ensures that i.e. 2003 has only 52 weeks. but these two prove it wrong: Select datepart(ww,'2003/12/31') --(wednesday -> returns 53) Select datepart(ww,'2004/1/1') --(thursday -> returns 1) Well - the weeknumber does not change in the middle of the week. Since
7
15148
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 attached), yet when I ran it for 28/09/2003 (UK date format) it returned Week 39. I would have expected it to return Week 40. However, I'm really stuck and my head is busting over this, so any pointers would be gratefully appreciated. Many thanks...
6
288
by: CryingFreeman | last post by:
Hi everyone, I started in access just a copple of weeks ago, to automise my ecell DVD database.So I could make forms, ans reports.. Thought it would be easy, but I'm trying nog for weeks and I think I have a bad base to start from. First, I made 3 tables: - Acteurs: acteur ID + acteur - Genres: genre ID + genre
9
1330
by: Alan Silver | last post by:
hello, I am writing my first real ASP.NET application, but am getting a bit confused with ADO.NEt and the best way to use it. My old method (with Classic ASP) was to have a function that you called like ... Set rsSomething = GrabRS("select * from mytable")
11
3940
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation a table with columns and rows
2
1804
by: Bull | last post by:
Hi, Is there a code that converts a whole number to Years and Weeks only? Thanks, Bull
11
1939
by: Neo Morpheous | last post by:
Ok, first lets start with some definitions: By "Expert", I mean someone who : 1). Is familiar with and understands the *MAJOR* concepts/philosopies underlying C# (and possible .Net as a whole - over and above CLI, CTS etc) 2). Knows which libraries to use for common and maybe not so common tasks 3). Can convincingly pass a C# technical interview (without having
14
19063
by: Tommy Jakobsen | last post by:
Hi. Is there a method in .NET that takes "year" as an argument and returns the total number of weeks in that year? For culture da-DK (Danish). Thanks in advance. Tommy.
4
10828
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
0
9314
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9015
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7953
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.