﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Rob Scholl / Article Discussions / Article Discussions by Author  / Finding next or previous nth business day excluding weekends / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 12:23:49 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>Hi,Thanks for the code. It really useful.Can you please explain the logic, so it will be easy to understand how it works. When @days are less than 0 you have done    SELECT @weeks = (datepart (dw, @date) + @days - 6)/5and when @days are greater than 0then   SELECT @weeks = (DATEPART (dw, @date) + @days - 2)/5how it works.Thanks &amp; Regards,</description><pubDate>Mon, 13 Feb 2012 00:19:14 GMT</pubDate><dc:creator>Jyots</dc:creator></item><item><title>RE: Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>What about holidays?Your best bet for this kind of thing is a calendar table.  Lots of uses, this is one of them.</description><pubDate>Thu, 20 Aug 2009 14:20:43 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>This is really great!!! Good Work!</description><pubDate>Thu, 20 Aug 2009 14:07:43 GMT</pubDate><dc:creator>Sherrill Herron</dc:creator></item><item><title>RE: Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>Thanks for this. smart programming.</description><pubDate>Tue, 23 Jun 2009 22:01:58 GMT</pubDate><dc:creator>Bimal Fernando</dc:creator></item><item><title>RE: Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>this is really great!! good work</description><pubDate>Tue, 23 Jun 2009 21:59:33 GMT</pubDate><dc:creator>Udula Karunathilake</dc:creator></item><item><title>Finding next or previous nth business day excluding weekends</title><link>http://www.sqlservercentral.com/Forums/Topic740730-253-1.aspx</link><description>declare @date datetimedeclare @days intdeclare @weeks intselect @date = '2009-06-21'select @days = 1if (@days &lt; 0)begin	if datepart (dw, @date) = 1		select @date = dateadd (d, -1, @date)	select @weeks = (datepart (dw, @date) + @days - 6)/5endelsebegin	if datepart (dw, @date) = 7		select @date = dateadd (d, 1, @date)	select @weeks = (datepart (dw, @date) + @days - 2)/5endselect dateadd (d, @days + (@weeks*2), @date)</description><pubDate>Tue, 23 Jun 2009 21:56:53 GMT</pubDate><dc:creator>maluthwatta</dc:creator></item></channel></rss>