Click here to Skip to main content
15,396,239 members
Articles / Programming Languages / Objective C
Posted 22 Mar 2004


15 bookmarked

CWeek - A Class for Getting the weekday and weeknumber

Rate me:
Please Sign up or sign in to vote.
3.93/5 (10 votes)
22 Mar 20041 min read
Getting the weekday and weeknumber


This is my first attempt ever to write an article of any kind. I don't have much experience in programming, but I would love some feedback about this article in order to learn. English is not my primary language, so be nice to me. :-)


I'm currently working on a calendar application with a friend of mine, and knowing the weekday and the weeknumber is somehow fundamental. ;)

I can't remember where I found the algorithms and information necessary to know how to retrieve the weekday and weeknumber, but if you know, then contact me and I will give the person credits for it.

How to use CWeek

CWeek is easy to use. First, declare an instance of the object.

CWeek date;

After this, you should set the date. For example, October 15, 2004.


To retrieve the weekday or the weeknumber, simply use:

nWeeknumber = date.getWeeknumber();
nWeekday = date.getWeekday();


  • 23rd March, 2004: Initial version


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Patrik Svensson
Software Developer
Sweden Sweden
No Biography provided

Comments and Discussions

GeneralWhich week number Pin
Willzyba22-Nov-04 4:12
MemberWillzyba22-Nov-04 4:12 
GeneralSome Comments Pin
Johann Gerell25-Mar-04 11:37
MemberJohann Gerell25-Mar-04 11:37 
GeneralRe: Some Comments Pin
Patrik Svensson26-Mar-04 4:54
MemberPatrik Svensson26-Mar-04 4:54 
GeneralWhy not base this class on CDateTime Pin
Gerard Nicol23-Mar-04 13:47
MemberGerard Nicol23-Mar-04 13:47 
GeneralRe: Why not base this class on CDateTime Pin
Gerard Nicol23-Mar-04 13:55
MemberGerard Nicol23-Mar-04 13:55 
GeneralRe: Why not base this class on CDateTime Pin
Eric Lapouge23-Mar-04 20:37
MemberEric Lapouge23-Mar-04 20:37 
GeneralRe: Why not base this class on CDateTime Pin
Johann Gerell25-Mar-04 11:39
MemberJohann Gerell25-Mar-04 11:39 
GeneralMisc comments Pin
Eric Lapouge23-Mar-04 5:50
MemberEric Lapouge23-Mar-04 5:50 
English, just like for you is not my primary language, but I read it more easily than swedish...So I'm unable to read any comment from your code!

Beside that, I saw two problems:
First, the way used to calculate the leap year is wrong (just check for 2000!) The correct way is:
(Year % 4 = 0) AND ((Year % 100 <> 0) OR (Year % 400 = 0))
Second, the way to calculate the first week of the year is country dependent (search for example in then MSDN with the keywords GetLocaleInfo LOCALE_IFIRSTWEEKOFYEAR).

Could you correct these points?

Hmmm | :| Eric
GeneralRe: Misc comments Pin
Patrik Svensson23-Mar-04 6:00
MemberPatrik Svensson23-Mar-04 6:00 
GeneralRe: Misc comments Pin
Eric Lapouge23-Mar-04 6:26
MemberEric Lapouge23-Mar-04 6:26 
GeneralKISS - Keep it simply stated Pin
NGS 54967223-Mar-04 5:36
MemberNGS 54967223-Mar-04 5:36 
GeneralRe: KISS - Keep it simply stated Pin
Patrik Svensson23-Mar-04 6:08
MemberPatrik Svensson23-Mar-04 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.