Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Get the week number of a given date

The C# method uses the DateTime object to get the week number of a given date. The number returned is dependent on the culture of the target machine.

On Wednesday, January 9th 2008 at 10:51 PM
By Andrew Pociu (View Profile)
*****   (Rated 4.8 with 15 votes)
Contextual Ads
More C# Resources
Advertisement
  1. public static int GetWeekNumber(DateTime dtPassed)
  2. {
  3.         CultureInfo ciCurr = CultureInfo.CurrentCulture;
  4.         int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
  5.         return weekNum;
  6. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by dgdsg on Friday, January 11th 2008 at 01:52 AM

dsfgdsfg

by Mc_Topaz on Friday, June 20th 2008 at 07:37 AM

Excellent solution!

That example was very helpfull.

Don't forget to add: using System.Globalization;

by Ranjith on Tuesday, September 30th 2008 at 10:54 PM

Thanks for giving such a nice thing

by Faruz on Thursday, December 18th 2008 at 08:11 AM

Thanks!!!!

by Lars G. on Monday, January 26th 2009 at 06:43 AM

Would be nice if this actually worked in all cultures - but it doesn't.

by cwrinn on Monday, March 2nd 2009 at 11:42 AM

Re: Lars

Would be nice if you detailed why/when it doesn't. Please, be Open with your knowledge. ;)

by Lars G. on Tuesday, March 3rd 2009 at 06:17 AM

Yes, of course; sorry.

It fails because Microsoft's function simply does not return the correct weeknumber; at least not in my country. I live in Denmark, and it fails to get the first and last week of the year right, seemingly Every time.

by Taylor on Wednesday, July 8th 2009 at 04:37 PM

Thanks a lot for posting this! One point about culture dependence is DayOfWeek.Monday is not the right choice for some cultures. DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek will give you the DayOfWeek enum value that is culture dependent. Lars, try using CalendarWeekRule.FirstDay instead of FirstFourDayWeek, that gave me the results I was looking for.

by Sjums on Saturday, August 15th 2009 at 03:09 AM

What is dtPassed?

by sitaram on Wednesday, October 14th 2009 at 07:56 AM

i need to display week number of month

can any one post this answer

by cwrinn on Wednesday, October 14th 2009 at 07:20 PM

Take the first, last, middle, or whatever day from the month and run that through the above function

by Steve on Tuesday, November 10th 2009 at 01:24 PM

Thanks for being so helpful!

by Patricio on Tuesday, January 26th 2010 at 04:45 PM

Use CreateSpecificCulture("no")

For ISO-8601

by Ghulam Qadir on Tuesday, March 16th 2010 at 07:52 AM

Thanks

by mams160 on Wednesday, May 19th 2010 at 07:25 AM

Thanks for this code snippet it's very usefull

by SuperGypo on Wednesday, June 23rd 2010 at 08:20 AM

Good work thanks :)
This might be useful for some to work it the other way - date of week: http://stackoverflow.com/questions/662379/calculate-date-from-week-number

by ahmed ali on Wednesday, July 7th 2010 at 08:05 AM

thank u v much realy this sample example make me do what i want effortless

by a'_ on Wednesday, July 7th 2010 at 08:14 AM

g'__

by sonu on Friday, August 20th 2010 at 06:18 AM

Hi If you want a day number of week for current date then you can simply do

DatetTime viewDate = DateTime.Now;
int weekday = (int)viewDate.DayOfWeek;
will give you 5 - for Friday and so forth.

Hope it will be helpful to somebody who just want to do simple things.

by Shakil Ahmed on Monday, October 11th 2010 at 04:57 AM

Thanks.Nice and quick solution

by Mohsen on Tuesday, November 23rd 2010 at 05:10 AM

Get the week number of DateTime

by rahuljain on Thursday, April 7th 2011 at 03:10 AM

it's really good.

by Chaitanya on Monday, April 18th 2011 at 03:35 PM

Superb. Thanks alot!!!

by Darragh on Tuesday, July 5th 2011 at 08:16 AM

Cheers!

by college stories on Saturday, August 13th 2011 at 07:24 AM

Your journal is so municipality that every one would undergo pleasure to valuation comments. So am I. Thanks.

by Song Dedication on Tuesday, August 16th 2011 at 01:30 AM

I somebody been municipality out any of your posts and i can rely pretty groovy move. I cognition definitely bookmark your powerfulness.

by Testking SY0-301 on Thursday, September 15th 2011 at 04:08 AM

Your post looks great! I enjoyed.Thanks you for sharing. I love it.

by Phen375 on Monday, December 19th 2011 at 06:00 PM

Your personal know-how and kindness in maneuvering every part was tremendous. I am not sure what I would've done if I hadn't encountered such a solution like this. I'm able to at this time look ahead to my future. Thanks a lot so much for the specialized and result oriented help. I won't hesitate to endorse the blog to anybody who desires assistance on this topic.

by GenF20 Plus on Monday, December 19th 2011 at 06:02 PM

Your personal know-how and kindness in maneuvering every part was tremendous. I am not sure what I would've done if I hadn't encountered such a solution like this. I'm able to at this time look ahead to my future. Thanks a lot so much for the specialized and result oriented help. I won't hesitate to endorse the blog to anybody who desires assistance on this topic.

by GenFX on Monday, December 19th 2011 at 06:03 PM

Your personal know-how and kindness in maneuvering every part was tremendous. I am not sure what I would've done if I hadn't encountered such a solution like this. I'm able to at this time look ahead to my future. Thanks a lot so much for the specialized and result oriented help. I won't hesitate to endorse the blog to anybody who desires assistance on this topic.

by Teeth Whitening Reviews on Tuesday, December 20th 2011 at 01:39 AM

I truly wanted to write a quick message to thank you for some of the splendid points you are showing at this website. My long internet investigation has at the end been compensated with sensible facts and techniques to share with my family and friends.

by Human Growth Hormone on Tuesday, December 20th 2011 at 01:41 AM

I truly wanted to write a quick message to thank you for some of the splendid points you are showing at this website. My long internet investigation has at the end been compensated with sensible facts and techniques to share with my family and friends.

by Best Diet Pills on Tuesday, December 20th 2011 at 01:46 AM

I would believe that we visitors are truly blessed to dwell in a wonderful network with many wonderful professionals with very beneficial hints. I feel extremely privileged to have seen the web pages and look forward to many more pleasurable times reading here. Thank you once again for everything.

by HGH Advanced on Tuesday, December 20th 2011 at 01:54 AM

I would believe that we visitors are truly blessed to dwell in a wonderful network with many wonderful professionals with very beneficial hints. I feel extremely privileged to have seen the web pages and look forward to many more pleasurable times reading here. Thank you once again for everything.

by Dental White on Tuesday, December 20th 2011 at 01:57 AM


Thanks so much for providing individuals with an extremely remarkable possiblity to read critical reviews from this web site. It is always so beneficial plus jam-packed with a great time for me personally and my office friends to search the blog at the least three times in one week to see the fresh secrets you will have.

by Pure Acai Berry Max on Tuesday, December 20th 2011 at 01:58 AM


Thanks so much for providing individuals with an extremely remarkable possiblity to read critical reviews from this web site. It is always so beneficial plus jam-packed with a great time for me personally and my office friends to search the blog at the least three times in one week to see the fresh secrets you will have.

by Ultimate Maqui Berry on Tuesday, December 20th 2011 at 02:01 AM

I am just always happy with your good tips and hints served by you. Some 1 areas in this article are undeniably the finest I've had.

by Proactol Plus on Tuesday, December 20th 2011 at 02:04 AM

I am just always happy with your good tips and hints served by you. Some 1 areas in this article are undeniably the finest I've had.

by Provacyl on Tuesday, December 20th 2011 at 02:10 AM

I am just always happy with your good tips and hints served by you. Some 1 areas in this article are undeniably the finest I've had.

by Nuratrim on Tuesday, December 20th 2011 at 02:13 AM

Thanks a lot for providing individuals with remarkably special possiblity to read critical reviews from this web site. It can be very kind plus packed with a great time for me personally and my office mates to visit your site no less than three times weekly to study the newest tips you have.

by Capsiplex on Tuesday, December 20th 2011 at 02:20 AM

Thanks a lot for providing individuals with remarkably special possiblity to read critical reviews from this web site. It can be very kind plus packed with a great time for me personally and my office mates to visit your site no less than three times weekly to study the newest tips you have.

by on Tuesday, January 17th 2012 at 01:09 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view

by Houston Criminal Lawyer on Monday, April 2nd 2012 at 05:03 PM

I truly wanted to write a quick message to thank you for some of the splendid points you are showing at this website. My long internet investigation has at the end been compensated with sensible facts and techniques to share with my family and friends.

by Coach Outlet Online on Monday, June 11th 2012 at 02:20 AM

http://www.getscoachoutletonline.org/ Coach Outlet Online
http://www.coachoutlets-canadas.org/ Coach Outlet Online
http://www.coachoutletpursea.org/ Coach Bags Outlet
http://www.coachoutletonline-purse.net/ Cheap Coach Handbags
http://www.coachfactorye.net/ Coach Factory
http://www.coachoutletusonline2012.net/ coach outlet online
http://www.louisvuittonpurse-outlets.net/ louis vuitton bags
http://www.coachoutlets4u.org/ coach outlet store online
http://www.coachfactorystorea.com/ Coach Factory Outlet
http://www.coachoutletusshop.org/ coach outlet
http://www.buycoachoutletinfactory.org/ coach factory outlet

by writing a essay on Wednesday, August 29th 2012 at 01:11 AM

It is so lucky to read your blog,it is full of useful message.I wish we both can do better in the future.It great honor if you can visit our website,and give us some suggestion. writing a essay

by ipad voice recognitio on Tuesday, October 2nd 2012 at 02:05 AM

mates to visit your site no less than three times weekly to study the newest tips you have.

by http://www.genesishealthinstitute.com/testosterone.php on Thursday, November 1st 2012 at 05:23 AM

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.http://www.genesishealthinstitute.com/testosterone.php

by Tapio on Friday, January 11th 2013 at 08:14 AM

Hi,

I can't get GetWeekOfYear function to work right. It gives the wrong week number at the end of year if the date is December 31, 2012.

My country is Finland, so the culture should be "fi". We use here the rule that first week of year is the first week that has four days on the year. The first day of week is monday. I think my settings are right. This still gives the wrong answer. I have the same problem as Lars.

Dim ciCurr As CultureInfo = CultureInfo.CreateSpecificCulture("fi")
Dim weekNum As Int32 = ciCurr.Calendar.GetWeekOfYear( _
dtValue, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)

by Raghu on Tuesday, May 14th 2013 at 06:14 AM

public int GetWeekOfYear(DateTime todayDate)
{
int days = todayDate.DayOfYear;
float result = days / 7;
result=result 1;
Response.Write(result.ToString());
return Convert.ToInt32(result);
}

just pass the current date then u will get the current week number....

by papersmart.net on Wednesday, June 5th 2013 at 09:47 PM

College graduates are grateful for competent ideas and clever materials. Not so many are aware of this fact. Reasonably cheap essay writer service is not likely to be underestimated by student.


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C# Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Ads

From the creators of Geekpedia, a revolutionary new coupon website!

BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.

Coupons
Discover Geekpedia
Other Resources