<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Method for adding working days to a date'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Sat, 18 May 2013 20:52:39 GMT</pubDate>
<item>
<title>ybastiand said on 7/2/10</title>
<link>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</link>
<description><![CDATA[ There is a bug in comment from MLaritz, at least when I change the method to be non extension. Fix is to assign the result of date.AddDays back in the date variable.

Here is my solution (unit tested):
		/// 
		/// Add or remove some business days to a date time.
		/// 
		/// 
		/// 
		/// 
		public static DateTime AddBusinessDays(DateTime date, int days)
		{
			int direction = (days < 0) ? -1 : 1;

			while (days != 0)
			{
				date = date.AddDays(direction);
				if (date.DayOfWeek != DayOfWeek.Saturday &amp;&amp; date.DayOfWeek != DayOfWeek.Sunday)
				{
					days -= direction;
				}
			}

			return date;
		} ]]></description>
<pubDate>Fri, 02 Jul 2010 05:13:48 GMT</pubDate>
<guid>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</guid>
</item>
<item>
<title>ybastiand said on 7/2/10</title>
<link>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</link>
<description><![CDATA[ There is a bug in comment from MLaritz, at least when I change the method to be non extension. Fix is to assign the result of date.AddDays back in the date variable.

Here is my solution (unit tested):
		/// 
		/// Add or remove some business days to a date time.
		/// 
		/// 
		/// 
		/// 
		public static DateTime AddBusinessDays(DateTime date, int days)
		{
			int direction = (days < 0) ? -1 : 1;

			while (days != 0)
			{
				date = date.AddDays(direction);
				if (date.DayOfWeek != DayOfWeek.Saturday &amp;&amp; date.DayOfWeek != DayOfWeek.Sunday)
				{
					days -= direction;
				}
			}

			return date;
		} ]]></description>
<pubDate>Fri, 02 Jul 2010 05:13:48 GMT</pubDate>
<guid>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</guid>
</item>
<item>
<title>MLaritz said on 3/4/10</title>
<link>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</link>
<description><![CDATA[ You can simplify this by not using nWeekDay and just using nDays.  I created an extension method:

    public static class DateTimeExtensions
    {
        public static DateTime AddBusinessDays(this DateTime date, int days)
        {
            int direction = days < 0 ? -1 : 1;

            while(days != 0)
            {
                date.AddDays(direction);
                if(date.DayOfWeek != DayOfWeek.Saturday &amp;&amp; date.DayOfWeek != DayOfWeek.Sunday)
                {
                    days -= direction;
                }
            }

            return date;
        }
    } ]]></description>
<pubDate>Thu, 04 Mar 2010 12:22:06 GMT</pubDate>
<guid>http://snipplr.com/view/12420/method-for-adding-working-days-to-a-date/</guid>
</item>
</channel>
</rss>