How do I calculate the week number given a date?

Posted by GH on Stack Overflow See other posts from Stack Overflow or by GH
Published on 2008-11-08T16:02:59Z Indexed on 2010/05/11 21:04 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

If I have a date, how do I calculate the week number for that date within that year?

For example, in 2008, January 1st to January 6th are in week 1 and January 7th to the 13th are in week 2, so if my date was January 10th 2008, my week number would be 2.

An algorithm would be great to get me started and sample code would also help - I'm developing in C++ on Windows.

Related:

Getting week number off a date in MS SQL Server 2005?

© Stack Overflow or respective owner

Related posts about time

Related posts about algorithm