<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month</title>
	<atom:link href="http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gourav</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51257</link>
		<dc:creator>Gourav</dc:creator>
		<pubDate>Fri, 24 Apr 2009 05:32:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51257</guid>
		<description>thanks bro... you hav done it....thank you very very much...
Regards
Gourav</description>
		<content:encoded><![CDATA[<p>thanks bro&#8230; you hav done it&#8230;.thank you very very much&#8230;<br />
Regards<br />
Gourav</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51251</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Thu, 23 Apr 2009 16:31:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51251</guid>
		<description>@gourav, here&#039;s a quick shot:
CREATE FUNCTION UDFDays(@mm tinyint,@yy smallint,@dyw varchar(9))
RETURNS TABLE
AS
 RETURN
 WITH
	Data(The_Date)
 AS
	(
	 SELECT CONVERT(smalldatetime, CAST(@mm as varchar(2)) + &#039;/01/&#039; + CAST(@YY as varchar(4)) , 101)
	),
	Days_In_Month
 AS
	(
	 SELECT The_Date, DATEADD(d, -1, DATEADD(m, 1, The_Date)) Next_Month FROM Data
	 UNION ALL
	 SELECT DATEADD(d, 1, The_Date), Next_Month FROM Days_In_Month WHERE The_Date &lt; Next_Month
	)
 SELECT
		DATEPART(d, The_Date) Day_Number
 FROM
		Days_In_Month
 WHERE
		DATENAME(dw, The_Date) =  @dyw;
GO</description>
		<content:encoded><![CDATA[<p>@gourav, here&#8217;s a quick shot:<br />
CREATE FUNCTION UDFDays(@mm tinyint,@yy smallint,@dyw varchar(9))<br />
RETURNS TABLE<br />
AS<br />
 RETURN<br />
 WITH<br />
	Data(The_Date)<br />
 AS<br />
	(<br />
	 SELECT CONVERT(smalldatetime, CAST(@mm as varchar(2)) + &#8216;/01/&#8217; + CAST(@YY as varchar(4)) , 101)<br />
	),<br />
	Days_In_Month<br />
 AS<br />
	(<br />
	 SELECT The_Date, DATEADD(d, -1, DATEADD(m, 1, The_Date)) Next_Month FROM Data<br />
	 UNION ALL<br />
	 SELECT DATEADD(d, 1, The_Date), Next_Month FROM Days_In_Month WHERE The_Date &lt; Next_Month<br />
	)<br />
 SELECT<br />
		DATEPART(d, The_Date) Day_Number<br />
 FROM<br />
		Days_In_Month<br />
 WHERE<br />
		DATENAME(dw, The_Date) =  @dyw;<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gourav</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51249</link>
		<dc:creator>Gourav</dc:creator>
		<pubDate>Thu, 23 Apr 2009 15:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51249</guid>
		<description>Re post:... slight mistake frm my side...

hi.. experts… i need a similar UDF…
my req is…. if i give 3 param’s to the UDF.. like..
“month,year and dayofweek” then i should get a list of that day fom the given month,year

ex. for April 2009 Sunday
UDFDays(@mm,@yy,@dyw)
i.e UDFDays(04,2009,’Sunday’)
then i should get list as.. 

5
12
19
26
i.e… the dates from the month given for weekday.. like for Apil 2009 Saturday..
i expect..esult as 

4
11
18
25

etc…
thanks in advance…</description>
		<content:encoded><![CDATA[<p>Re post:&#8230; slight mistake frm my side&#8230;</p>
<p>hi.. experts… i need a similar UDF…<br />
my req is…. if i give 3 param’s to the UDF.. like..<br />
“month,year and dayofweek” then i should get a list of that day fom the given month,year</p>
<p>ex. for April 2009 Sunday<br />
UDFDays(@mm,@yy,@dyw)<br />
i.e UDFDays(04,2009,’Sunday’)<br />
then i should get list as.. </p>
<p>5<br />
12<br />
19<br />
26<br />
i.e… the dates from the month given for weekday.. like for Apil 2009 Saturday..<br />
i expect..esult as </p>
<p>4<br />
11<br />
18<br />
25</p>
<p>etc…<br />
thanks in advance…</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gourav</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51247</link>
		<dc:creator>Gourav</dc:creator>
		<pubDate>Thu, 23 Apr 2009 14:38:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-51247</guid>
		<description>hi.. experts... i need a similar UDF...
my req is....  if i give 3 param&#039;s to the UDF.. like..
&quot;month,year and dayofweek&quot; then i should get a list of that day fom the given month,year

ex.  for April 2009 Sunday 
 UDFDays(@mm,@yy,@dyw) 
i.e UDFDays(04,2009,&#039;Sunday&#039;)
then i should get list as.. 

6
13
20
27

i.e... the dates from the month given for weekday..  like for Apil 2009 Saturday.. 
i expect..esult as 

5
12
19
26

etc...
thanks in advance...</description>
		<content:encoded><![CDATA[<p>hi.. experts&#8230; i need a similar UDF&#8230;<br />
my req is&#8230;.  if i give 3 param&#8217;s to the UDF.. like..<br />
&#8220;month,year and dayofweek&#8221; then i should get a list of that day fom the given month,year</p>
<p>ex.  for April 2009 Sunday<br />
 UDFDays(@mm,@yy,@dyw)<br />
i.e UDFDays(04,2009,&#8217;Sunday&#8217;)<br />
then i should get list as.. </p>
<p>6<br />
13<br />
20<br />
27</p>
<p>i.e&#8230; the dates from the month given for weekday..  like for Apil 2009 Saturday..<br />
i expect..esult as </p>
<p>5<br />
12<br />
19<br />
26</p>
<p>etc&#8230;<br />
thanks in advance&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - 2008 - Interview Questions and Answers - Part 2 Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-47465</link>
		<dc:creator>SQL SERVER - 2008 - Interview Questions and Answers - Part 2 Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Thu, 26 Feb 2009 11:55:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-47465</guid>
		<description>[...] A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a TSQL select command or a group of them gives us the capability to in essence create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets. (Read Here For Example) [...]</description>
		<content:encoded><![CDATA[<p>[...] A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a TSQL select command or a group of them gives us the capability to in essence create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets. (Read Here For Example) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-47247</link>
		<dc:creator>SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:10:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-47247</guid>
		<description>[...] SQL SERVER - UDF - User Defined Function - Get Number of Days in Month [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maheswaran</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-46057</link>
		<dc:creator>Maheswaran</dc:creator>
		<pubDate>Wed, 28 Jan 2009 10:23:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-46057</guid>
		<description>I want No.of days in a Month - Here i will give Month(2) and Year(2009),

so, there are two parameters.

Pls Give me the function</description>
		<content:encoded><![CDATA[<p>I want No.of days in a Month &#8211; Here i will give Month(2) and Year(2009),</p>
<p>so, there are two parameters.</p>
<p>Pls Give me the function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahesh K Rajan</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-43671</link>
		<dc:creator>Mahesh K Rajan</dc:creator>
		<pubDate>Mon, 13 Oct 2008 08:39:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-43671</guid>
		<description>We have already some built in functions avail, then why should we go behind all those steps...
Anyway, good logic... 
-Mahesh</description>
		<content:encoded><![CDATA[<p>We have already some built in functions avail, then why should we go behind all those steps&#8230;<br />
Anyway, good logic&#8230;<br />
-Mahesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: poleswar</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-40563</link>
		<dc:creator>poleswar</dc:creator>
		<pubDate>Mon, 21 Jul 2008 12:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-40563</guid>
		<description>EXCELLENT ...:))

EXACTLY SUITS MY REQUIREMENT

SUPERB 

THNX A LOT.........</description>
		<content:encoded><![CDATA[<p>EXCELLENT &#8230;:))</p>
<p>EXACTLY SUITS MY REQUIREMENT</p>
<p>SUPERB </p>
<p>THNX A LOT&#8230;&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishwanath</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-34207</link>
		<dc:creator>Vishwanath</dc:creator>
		<pubDate>Mon, 10 Mar 2008 09:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-34207</guid>
		<description>Just a modification to Doug&#039;s posting : 

CREATE FUNCTION [dbo].[ufn_GetDaysInMonth] (@CurrentDate DATETIME )
RETURNS INT
AS
BEGIN
DECLARE @RetDate INT
SET @RetDate = DAY(DATEADD(d, -DAY(DATEADD(m,1,@CurrentDate)),DATEADD(m,1,@CurrentDate)))
RETURN @RetDate
END


-- SELECT [dbo].[ufn_GetDaysInMonth] (&#039;2008/02/25&#039;)</description>
		<content:encoded><![CDATA[<p>Just a modification to Doug&#8217;s posting : </p>
<p>CREATE FUNCTION [dbo].[ufn_GetDaysInMonth] (@CurrentDate DATETIME )<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
DECLARE @RetDate INT<br />
SET @RetDate = DAY(DATEADD(d, -DAY(DATEADD(m,1,@CurrentDate)),DATEADD(m,1,@CurrentDate)))<br />
RETURN @RetDate<br />
END</p>
<p>&#8211; SELECT [dbo].[ufn_GetDaysInMonth] (&#8216;2008/02/25&#8242;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thiru</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-15182</link>
		<dc:creator>Thiru</dc:creator>
		<pubDate>Fri, 12 Oct 2007 03:04:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-15182</guid>
		<description>Hi pinaldave, 

Thank you very much</description>
		<content:encoded><![CDATA[<p>Hi pinaldave, </p>
<p>Thank you very much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-13400</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 20 Sep 2007 15:37:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-13400</guid>
		<description>Try this one-liner:
CREATE FUNCTION [dbo].[ufn_GetDaysInMonth](
@CurrentDate DATETIME )
RETURNS INT
AS
BEGIN
RETURN DAY(DATEADD(d, -DAY(DATEADD(m,1,@dt)),DATEADD(m,1,@dt))) 
END</description>
		<content:encoded><![CDATA[<p>Try this one-liner:<br />
CREATE FUNCTION [dbo].[ufn_GetDaysInMonth](<br />
@CurrentDate DATETIME )<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
RETURN DAY(DATEADD(d, -DAY(DATEADD(m,1,@dt)),DATEADD(m,1,@dt)))<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Munna Sarfraz Ahmad</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-12931</link>
		<dc:creator>Munna Sarfraz Ahmad</dc:creator>
		<pubDate>Mon, 17 Sep 2007 10:49:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-12931</guid>
		<description>Hi This User defined function will return the no. of days in a month

CREATE FUNCTION [dbo].[ufn_GetDaysInMonth](
	 	@CurrentDate DATETIME )
		RETURNS INT
	AS
	BEGIN
	DECLARE @ReturnDays INT
		SET @ReturnDays =
				CASE 	WHEN MONTH(@CurrentDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
					WHEN MONTH(@CurrentDate) IN (4, 6, 9, 11) THEN 30
						ELSE 
							CASE WHEN (YEAR(@CurrentDate) % 4 = 0 AND YEAR(@CurrentDate) % 100 != 0) OR (YEAR(@CurrentDate) % 400 = 0)	THEN 29
								ELSE 28 
							END
				END
		RETURN @ReturnDays
	END

--SELECT dbo.ufn_GetDaysInMonth(GETDATE()) No_Of_Days_In_Month
GO</description>
		<content:encoded><![CDATA[<p>Hi This User defined function will return the no. of days in a month</p>
<p>CREATE FUNCTION [dbo].[ufn_GetDaysInMonth](<br />
	 	@CurrentDate DATETIME )<br />
		RETURNS INT<br />
	AS<br />
	BEGIN<br />
	DECLARE @ReturnDays INT<br />
		SET @ReturnDays =<br />
				CASE 	WHEN MONTH(@CurrentDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31<br />
					WHEN MONTH(@CurrentDate) IN (4, 6, 9, 11) THEN 30<br />
						ELSE<br />
							CASE WHEN (YEAR(@CurrentDate) % 4 = 0 AND YEAR(@CurrentDate) % 100 != 0) OR (YEAR(@CurrentDate) % 400 = 0)	THEN 29<br />
								ELSE 28<br />
							END<br />
				END<br />
		RETURN @ReturnDays<br />
	END</p>
<p>&#8211;SELECT dbo.ufn_GetDaysInMonth(GETDATE()) No_Of_Days_In_Month<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryan</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-12273</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Wed, 12 Sep 2007 21:08:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-12273</guid>
		<description>Hello, Expert

I&#039;m using Transact-Query, how I select a particular month out of in different years in the database? 

The format column field 2005/08/26.......

thanks you
ryan,</description>
		<content:encoded><![CDATA[<p>Hello, Expert</p>
<p>I&#8217;m using Transact-Query, how I select a particular month out of in different years in the database? </p>
<p>The format column field 2005/08/26&#8230;&#8230;.</p>
<p>thanks you<br />
ryan,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-11991</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Mon, 10 Sep 2007 16:09:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-11991</guid>
		<description>Thanks Simon,

I have used similar logic many times. I just decided to do something different. You can check other datetime related articles here.

http://blog.sqlauthority.com/tag/sql-datetime/

Regards,
Pinal Dave ( http://www.SQLAuthority.com )</description>
		<content:encoded><![CDATA[<p>Thanks Simon,</p>
<p>I have used similar logic many times. I just decided to do something different. You can check other datetime related articles here.</p>
<p><a href="http://blog.sqlauthority.com/tag/sql-datetime/" rel="nofollow">http://blog.sqlauthority.com/tag/sql-datetime/</a></p>
<p>Regards,<br />
Pinal Dave ( <a href="http://www.SQLAuthority.com" rel="nofollow">http://www.SQLAuthority.com</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Worth</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-11988</link>
		<dc:creator>Simon Worth</dc:creator>
		<pubDate>Mon, 10 Sep 2007 15:38:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comment-11988</guid>
		<description>You really don&#039;t need to do the math, you can just get the last day of the month using built in date functions and assign that to your return variable.  This is built in for you so you don&#039;t have to worry about leap years or anything

CREATE FUNCTION [dbo].[udf_GetNumDaysInMonth] ( @myDateTime DATETIME )
RETURNS INT
AS
BEGIN
      DECLARE @rtDate INT
      SET @rtDate = DATEPART(dd, DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,@myDateTime)+1, 0)))
RETURN @rtDate
END
GO</description>
		<content:encoded><![CDATA[<p>You really don&#8217;t need to do the math, you can just get the last day of the month using built in date functions and assign that to your return variable.  This is built in for you so you don&#8217;t have to worry about leap years or anything</p>
<p>CREATE FUNCTION [dbo].[udf_GetNumDaysInMonth] ( @myDateTime DATETIME )<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
      DECLARE @rtDate INT<br />
      SET @rtDate = DATEPART(dd, DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,@myDateTime)+1, 0)))<br />
RETURN @rtDate<br />
END<br />
GO</p>
]]></content:encoded>
	</item>
</channel>
</rss>
