Solved

Getting the Week Number for the Year Given a Date

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

12 Experts available now in Live!

Get 1:1 Help Now