Click here to Skip to main content
12,358,497 members (63,895 online)
Click here to Skip to main content
Alternatives (3)
Add your own
alternative version

Tagged as

Stats

30.3K views
5 bookmarked
Posted

DateTime Extension Method to Give Week Number

, 14 Jul 2011 CPOL
Strangely, the .NET DateTime does not provide a Week Number. This extension rectifies this.

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

6 Sep 2011
Bib34770
What about that :CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(pd_date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
8 Sep 2011
Jani Giannoudis
Here another approach taken from my article Time Period Library for .NET[^], which returns addditional the year of the week.// ------------------------------------------------------------------------public enum YearWeekType{ Calendar, Iso8601,} // enum YearWeekType //...
19 Jul 2011
Gustav Brock
There certainly is a direct method in .NET to obtain the ISO week number. However, it is buggy, as ISO week numbering has been from VB 3.0 and Access Basic (of Access 1.0) through VBA of Office 2016, and not resolved in .NET. Fortunately, a tiny test for week 53 will get it right.

License

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

Share

About the Author

OriginalGriff
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 15 Jul 2011
Article Copyright 2011 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid