Solved

Getting the Week Number for the Year Given a Date

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Needing an event fired when a row is added on a datagridview 4 36
C# Error - Add Failed 12 78
What .NET website keeps me current? 9 54
Runtime Error 2 28
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now