?
Solved

Getting the Week Number for the Year Given a Date

Posted on 2006-11-01
3
Medium Priority
?
217 Views
Last Modified: 2010-08-05
I am trying to find a simple way to get the week number for a year, given a data in the format dd/mm/yyyy (e.g. 07/01/2006). The year will not necessarily be the curent year, it could be a past or future year. (This is what's giving me the problem).

Thanks!

0
Comment
Question by:marmaxx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Expert Comment

by:joechina
ID: 17852155
Try this

static int weekOfYear(DateTime dt)
{
     return (int)((int)(dt.DayOfYear + DateTime.ParseExact(dt.Year.ToString(), "yyyy", null).DayOfWeek) / 7 + 1);
}

Week is from Sunday to Saturday.

0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 total points
ID: 17852675
I think this can help you and show you the exact ISO way to do this:

http://konsulent.sandelien.no/VB_help/Week/

The only thing you have to add is the parsing of the date with:

DateTime date = DateTime.ParseExact ("07/01/2006", "dd/mm/yyyy", null);
0
 

Author Comment

by:marmaxx
ID: 17853017
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question