Click here to Skip to main content
16,004,806 members
Articles / Programming Languages / C#
Tip/Trick

Get week from Specific date

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
22 Apr 2010CPOL 10.4K   1   2
DateTime date = DateTime.Now;System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no");System.Globalization.Calendar cal = cult_info.Calendar;int weekNo = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule,...
DateTime date = DateTime.Now;

System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no");

System.Globalization.Calendar cal = cult_info.Calendar;

int weekNo = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralReason for my vote of 4 Good tip Pin
subodhkant2-Feb-11 2:50
subodhkant2-Feb-11 2:50 
GeneralReason for my vote of 2 I live in sweden where week numbers ... Pin
Per Söderlund7-Jul-10 8:56
Per Söderlund7-Jul-10 8:56 
Reason for my vote of 2
I live in sweden where week numbers start on mondays. and this code gives me weeknumber of 26 when its in fact weeknumber 27.Since friday saturday and sunday at week 1 is in fact week 53 last year.
I just copied it and returned weekNo into a messagebox.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.