Solved

Getting the Week Number for the Year Given a Date

Posted on 2006-11-01
3
214 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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