<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx</link><description>Several people have noticed that Calendar.GetWeekOfYear() is almost like the ISO 8601 week when passed CalendarWeekRule.FirstFourDayWeek and DayOfWeek.Monday , however it is a little bit different. Specifically ISO 8601 always has 7 day weeks. If the</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>ISO 8601 redux</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#525514</link><pubDate>Mon, 06 Feb 2006 11:32:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:525514</guid><dc:creator>Sorting It All Out</dc:creator><description>The other day, colleague Shawn Steele posted in his blog about the ISO 8601 Week of Year format in Microsoft...</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#1935787</link><pubDate>Fri, 23 Mar 2007 10:50:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1935787</guid><dc:creator>Jerome B.</dc:creator><description>&lt;P&gt;Hello, just an extended version with the year out parameter ...&lt;/P&gt;
&lt;P&gt;[code]&lt;/P&gt;
&lt;P&gt;/// &amp;lt;summary&amp;gt;&lt;/P&gt;
&lt;P&gt;/// Returns an ISO8601 week number&lt;/P&gt;
&lt;P&gt;/// &amp;lt;para&amp;gt;This presumes that weeks start with Monday. Week 1 is the 1st week of the year with a Thursday in it.&lt;/P&gt;
&lt;P&gt;/// &amp;lt;/para&amp;gt;References :&lt;/P&gt;
&lt;P&gt;/// &amp;lt;para&amp;gt;"ISO 8601 Week of Year format in Microsoft .Net" by Shawn Steele (&lt;A href="http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx" target=_new rel=nofollow&gt;http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;/// &amp;lt;/para&amp;gt;"DatePart result discrepancies when calculating ISO8601 week" by Steven Cheng (&lt;A href="http://www.eggheadcafe.com/conversationposter.aspx?messageid=27602745&amp;amp;groupid=435" target=_new rel=nofollow&gt;http://www.eggheadcafe.com/conversationposter.aspx?messageid=27602745&amp;amp;groupid=435&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;/// &amp;lt;/summary&amp;gt;&lt;/P&gt;
&lt;P&gt;/// &amp;lt;param name="date"&amp;gt;[in] Date whose the week number is required&amp;lt;/param&amp;gt;&lt;/P&gt;
&lt;P&gt;/// &amp;lt;param name="year"&amp;gt;[out] Year of the returned week number&amp;lt;/param&amp;gt;&lt;/P&gt;
&lt;P&gt;/// &amp;lt;returns&amp;gt;Week number of the specified date&amp;lt;/returns&amp;gt;&lt;/P&gt;
&lt;P&gt;public static int GetIso8601WeekOfYear(DateTime date, out int year)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;// Need a calendar. &amp;nbsp;Culture's irrelevent since we specify start day of week&lt;/P&gt;
&lt;P&gt;Calendar calendar = CultureInfo.InvariantCulture.Calendar;&lt;/P&gt;
&lt;P&gt;// Seriously cheat. &amp;nbsp;If its Monday, Tuesday or Wednesday, then it'll &lt;/P&gt;
&lt;P&gt;// be the same week# as whatever Thursday, Friday or Saturday are,&lt;/P&gt;
&lt;P&gt;// and we always get those right&lt;/P&gt;
&lt;P&gt;DayOfWeek day = calendar.GetDayOfWeek(date);&lt;/P&gt;
&lt;P&gt;if (day &amp;gt;= DayOfWeek.Monday &amp;amp;&amp;amp; day &amp;lt;= DayOfWeek.Wednesday)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;date = date.AddDays(3);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;year = date.Year;&lt;/P&gt;
&lt;P&gt;// Return the week of our adjusted day&lt;/P&gt;
&lt;P&gt;int weekNumber = calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);&lt;/P&gt;
&lt;P&gt;if((weekNumber &amp;gt;= 52) &amp;amp;&amp;amp; (date.Month &amp;lt; 12)) { year--; }&lt;/P&gt;
&lt;P&gt;return weekNumber;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;[/code]&lt;/P&gt;</description></item><item><title>Other way around...</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#4169221</link><pubDate>Wed, 01 Aug 2007 17:20:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4169221</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Neat, and simple! But how would one go about this the other way? taking an ISO8601 week date into a .NET/CLR DateTime struct again.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#5827020</link><pubDate>Fri, 02 Nov 2007 06:43:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5827020</guid><dc:creator>Ragesh</dc:creator><description>&lt;p&gt;hello sir/madam&lt;/p&gt;
&lt;p&gt;i have seen u r code and MS&lt;/p&gt;
&lt;p&gt;just im want to know which is right&lt;/p&gt;
&lt;p&gt;i want the number of week year for a particular year&lt;/p&gt;
&lt;p&gt;which code i wil use&lt;/p&gt;</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#6732352</link><pubDate>Tue, 11 Dec 2007 10:44:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6732352</guid><dc:creator>Wijnand</dc:creator><description>&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// Get the last WeekNumber of the Current Year.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// &amp;lt;returns&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// LastWeek Number&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// &amp;lt;/returns&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public int LastWeekOfYear()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Last day of year&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DateTime dt = new DateTime(DateTime.Now.Year, 12, 31);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Last week of year&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int lastWeek = GetIso8601WeekOfYear(dt);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (lastWeek == 1)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/// 31-12 is week 1 set the date a week back and get the last week.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt = dt.AddDays(-7);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lastWeek = GetIso8601WeekOfYear(dt);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return lastWeek;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#8997887</link><pubDate>Mon, 13 Oct 2008 15:27:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8997887</guid><dc:creator>Dr J R Stockton</dc:creator><description>&lt;p&gt;Wijnand : The last ISO week number of a year number is that of YYYY-12-28; no need to fumble.&lt;/p&gt;
&lt;p&gt;shawnste : The check in the code should be for at least 365.2425*400 days, say 150000 days. &amp;nbsp;MS VBS DatePart for WN gives two types of error, one being once in 400 years.&lt;/p&gt;
&lt;p&gt;My cited index links to a number of date pages.&lt;/p&gt;
&lt;p&gt;Jerome B : Right. An ISO WN routine needs to give also YN, and might as well give DN too. &amp;nbsp;It should be easy enough to write such *without* using GetWeekOfYear. &amp;nbsp;Algorithm is on my site, but I don't have or know Powershell/.NET.&lt;/p&gt;
&lt;p&gt;John : my site includes reverse algorithm, in JavaScript.&lt;/p&gt;</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#9897924</link><pubDate>Tue, 22 Sep 2009 12:23:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9897924</guid><dc:creator>osexpert</dc:creator><description>&lt;P&gt;Can this method be used to get weeks where first day of week is sunday as well, or is it just to be used where monday is first day of week?&lt;/P&gt;</description></item><item><title>re: ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx#9898093</link><pubDate>Tue, 22 Sep 2009 19:50:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898093</guid><dc:creator>shawnste</dc:creator><description>&lt;p&gt;You could do the same thing with Sunday (if you wanted the week number to roll over to the next year so there weren't partial week numbers), but then it wouldn't be ISO 8601. &amp;nbsp;The ISO standard starts with Mondays.&lt;/p&gt;
</description></item></channel></rss>