<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luke Hayler - SQL Server developer &#187; syntax</title>
	<atom:link href="http://www.lukehayler.com/tag/syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lukehayler.com</link>
	<description>A blog about Integration services, Reporting services, and the things that interest me</description>
	<lastBuildDate>Fri, 06 Aug 2010 10:19:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The DateAdd() Function in SSRS</title>
		<link>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/</link>
		<comments>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 08:00:36 +0000</pubDate>
		<dc:creator>Luke Hayler</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.lukehayler.com/?p=9</guid>
		<description><![CDATA[Getting acquainted
The DateAdd() function. According to BOL this &#8220;Returns a date to which a specified time interval has been added&#8221;. The structure of the function is as follows:
DateAdd(interval, number, date)
It&#8217;s a Date!
Like most first dates, getting to grips with this function and understanding its &#8216;needs&#8217; is a tricky process. Initially, you may have attempted to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Getting acquainted</strong></p>
<p>The DateAdd() function. According to BOL this &#8220;Returns a date to which a specified time interval has been added&#8221;. The structure of the function is as follows:</p>
<p><em>DateAdd(interval, number, date)</em></p>
<p><strong>It&#8217;s a Date!</strong></p>
<p>Like most first dates, getting to grips with this function and understanding its &#8216;needs&#8217; is a tricky process. Initially, you may have attempted to use the tried-and-trusted methods (aka &#8217;syntax&#8217;), <em>DateAdd(mm, 1, Now()). </em>No. Ok, let&#8217;s try <em>DateAdd(&#8216;mm&#8217;, 1, now())</em>. Nope. What about <em>DateAdd(month, 1, Now()). </em>Good luck with that&#8230;Yes. It&#8217;s a little mystifying.</p>
<p><strong>Score!</strong></p>
<p>There are a couple of ways to achieve the desired result with this function. 1.) use the <em>DateInterval</em> collection, or 2.) use the date part abbreviations. My recommendation? Use the DateInterval collection. Using the abbreviations, there is a chance that something will be calculated differently to what you&#8217;d expect (I explain a little further on). The <em>DateInterval</em> collection can be found in the Object Browser and looks like this:</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 297px"><img class="size-full wp-image-45" title="The DateInterval Collection" src="http://www.lukehayler.com/wp-content/uploads/2009/07/DateAdd_DateIntervals.jpg" alt="A list of all the Intervals in the DateInterval collection" width="287" height="237" /><p class="wp-caption-text">Fig 1. A list of all the Intervals in the DateInterval collection</p></div>
<p>&#8220;So how do you use this in the function?&#8221; I hear you ask.</p>
<p><em>=DateAdd(<strong>DateInterval.Month</strong>, 1, Today())</em> which gives you a date 1 month from today.</p>
<p>This will work for all the intervals listed in Fig 1. above.</p>
<p>If you don&#8217;t want to use this method and instead want to use the abbreviations then there are a few things to be weary of. For instance, using <em>DateAdd(&#8220;w&#8221;, 1, Today())</em> does not yield a date 1 <strong>week</strong> from today, but rather 1 <strong>day</strong> from today. This happens with a couple of other abbreviations as well. The reason is that &#8220;w&#8221; represents &#8220;weekday&#8221; not &#8220;week&#8221;. Here is an shortlist of the abbreviations that do work:</p>
<ul>
<li>Days ["dd"] &#8211; DateAdd(&#8220;dd&#8221;, 1, today())</li>
<li>Weeks ["ww"] &#8211; DateAdd(&#8220;ww&#8221;, 1, today())</li>
<li>Months ["mm"] &#8211; DateAdd(&#8220;mm&#8221;, 1, today())</li>
<li>Years ["yyyy"] &#8211; DateAdd(&#8220;yyyy&#8221;, 1, today())</li>
</ul>
<p>For a full list of abbreviations and further explanation, msdn delivers <a href="http://msdn.microsoft.com/en-us/library/cb7z8yf9(VS.85).aspx">here</a>.</p>
<p>Hopefully this clears up a little of the confusion surrounding the DateAdd() function and the intervals that need to be specified. Of course, if there are other methods that can be used or I&#8217;m all ears.</p>
<p>I like keep an open mind. When working with windows, one must.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
