<?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/"
		>
<channel>
	<title>Comments on: Total number of days in a month</title>
	<atom:link href="http://www.sqllion.com/2009/07/total-number-of-days-in-a-month/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqllion.com/2009/07/total-number-of-days-in-a-month/</link>
	<description>Welcome to the Database Jungle</description>
	<lastBuildDate>Fri, 03 Feb 2012 09:18:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Dan Ribar</title>
		<link>http://www.sqllion.com/2009/07/total-number-of-days-in-a-month/comment-page-1/#comment-946</link>
		<dc:creator>Dan Ribar</dc:creator>
		<pubDate>Tue, 09 Aug 2011 12:37:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqllion.com/?p=755#comment-946</guid>
		<description>Your first method is great except that it doesn&#039;t handle month 12 (since you can&#039;t add 1 to month 12).  I adjusted it as follows:


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
-- =============================================
-- Author: Internet
-- =============================================
ALTER FUNCTION [dbo].[getTotalDaysInMonth]
(
	-- Add the parameters for the function here
	@anydateofMonth DATETIME
)
RETURNS INT
AS
BEGIN
	-- Declare the return variable here
	DECLARE @totalDaysInMonth INT
	-- Add the T-SQL statements to compute the return value here
 
		DECLARE @givendate DATETIME
		SET @givendate = @anydateofMonth
 
		SET @givendate = case when MONTH(@givendate)=12 
			then STR(YEAR(@givendate)) + &#039;-&#039; + STR(1) + &#039;-01&#039;
			else STR(YEAR(@givendate)) + &#039;-&#039; + STR(MONTH(@givendate) + 1) + &#039;-01&#039;
			end 
		 
 
		SELECT @totalDaysInMonth = DATEPART(dd, DATEADD(DAY, -1, @givendate))
 
	-- Return the result of the function
	RETURN @totalDaysInMonth
 
END</description>
		<content:encoded><![CDATA[<p>Your first method is great except that it doesn&#8217;t handle month 12 (since you can&#8217;t add 1 to month 12).  I adjusted it as follows:</p>
<p>SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO</p>
<p>&#8211; =============================================<br />
&#8211; Author: Internet<br />
&#8211; =============================================<br />
ALTER FUNCTION [dbo].[getTotalDaysInMonth]<br />
(<br />
	&#8211; Add the parameters for the function here<br />
	@anydateofMonth DATETIME<br />
)<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
	&#8211; Declare the return variable here<br />
	DECLARE @totalDaysInMonth INT<br />
	&#8211; Add the T-SQL statements to compute the return value here</p>
<p>		DECLARE @givendate DATETIME<br />
		SET @givendate = @anydateofMonth</p>
<p>		SET @givendate = case when MONTH(@givendate)=12<br />
			then STR(YEAR(@givendate)) + &#8216;-&#8217; + STR(1) + &#8216;-01&#8242;<br />
			else STR(YEAR(@givendate)) + &#8216;-&#8217; + STR(MONTH(@givendate) + 1) + &#8216;-01&#8242;<br />
			end </p>
<p>		SELECT @totalDaysInMonth = DATEPART(dd, DATEADD(DAY, -1, @givendate))</p>
<p>	&#8211; Return the result of the function<br />
	RETURN @totalDaysInMonth</p>
<p>END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Omnibuzz</title>
		<link>http://www.sqllion.com/2009/07/total-number-of-days-in-a-month/comment-page-1/#comment-266</link>
		<dc:creator>Omnibuzz</dc:creator>
		<pubDate>Fri, 30 Oct 2009 10:34:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqllion.com/?p=755#comment-266</guid>
		<description>Method 4, maybe?

declare @InputDate datetime
set @InputDate = GetDate()
select dateadd(mm,datediff(mm,0,@InputDate)+ 1,0)-1 as last_day_of_month

-Omni</description>
		<content:encoded><![CDATA[<p>Method 4, maybe?</p>
<p>declare @InputDate datetime<br />
set @InputDate = GetDate()<br />
select dateadd(mm,datediff(mm,0,@InputDate)+ 1,0)-1 as last_day_of_month</p>
<p>-Omni</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sanjay</title>
		<link>http://www.sqllion.com/2009/07/total-number-of-days-in-a-month/comment-page-1/#comment-259</link>
		<dc:creator>sanjay</dc:creator>
		<pubDate>Sat, 10 Oct 2009 05:20:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqllion.com/?p=755#comment-259</guid>
		<description>Dears i write mannual coding for get total number of days 
see next

  public string GetNumberOfDays(DateTime strStartDate,DateTime strEndDate)
    {
          //Start Date
        string fStartDate = strStartDate.ToString();
        string fEndDate = strEndDate.ToString();
       string[] SD1=fStartDate.Split(&quot; &quot;.ToCharArray());
       string[] ED1 = fEndDate.Split(&quot; &quot;.ToCharArray());
          fStartDate =SD1[0].ToString();
          fEndDate =ED1[0].ToString();
          string[] StartDateArray = fStartDate.Split(&quot;/&quot;.ToCharArray());
          string[] EndDateArray = fEndDate.Split(&quot;/&quot;.ToCharArray());
          Int16  SDate =Convert.ToInt16(StartDateArray[1]);
          Int16 SMonth = Convert.ToInt16(StartDateArray[0]);
          Int16 SYear = Convert.ToInt16(StartDateArray[2]);
          //End Date
          Int16 EDate = Convert.ToInt16(EndDateArray[1]);
          Int16 EMonth = Convert.ToInt16(EndDateArray[0]);
          Int16 EYear = Convert.ToInt16(EndDateArray[2]);
        Int16  TotalDay = 0;
          string strTDays=&quot;&quot;;
        Int16  NumDayInMonth =Convert.ToInt16(DateTime.DaysInMonth(SYear, SMonth));
          if (SYear&lt;=EYear)
          {
              if (SMonth &lt;= EMonth)
              {

                  while (SDate !=EDate &amp;&amp; SMonth!=EMonth)
                  {
                      if (SDate  != NumDayInMonth)
                      {
                         SDate  = Convert.ToInt16(SDate+1) ;
                          TotalDay =Convert.ToInt16( TotalDay+1);
                      }
                      if (SDate  == NumDayInMonth)
                      {
                          SDate = 1;
                          SDate  =Convert.ToInt16(SDate+1);
                          SMonth =Convert.ToInt16(SMonth+1);
                          TotalDay = Convert.ToInt16(TotalDay+1);
                      }

                  }
                  strTDays =Convert.ToString(TotalDay+1);
                  
              }
          }
          return strTDays;
    }</description>
		<content:encoded><![CDATA[<p>Dears i write mannual coding for get total number of days<br />
see next</p>
<p>  public string GetNumberOfDays(DateTime strStartDate,DateTime strEndDate)<br />
    {<br />
          //Start Date<br />
        string fStartDate = strStartDate.ToString();<br />
        string fEndDate = strEndDate.ToString();<br />
       string[] SD1=fStartDate.Split(&#8221; &#8220;.ToCharArray());<br />
       string[] ED1 = fEndDate.Split(&#8221; &#8220;.ToCharArray());<br />
          fStartDate =SD1[0].ToString();<br />
          fEndDate =ED1[0].ToString();<br />
          string[] StartDateArray = fStartDate.Split(&#8220;/&#8221;.ToCharArray());<br />
          string[] EndDateArray = fEndDate.Split(&#8220;/&#8221;.ToCharArray());<br />
          Int16  SDate =Convert.ToInt16(StartDateArray[1]);<br />
          Int16 SMonth = Convert.ToInt16(StartDateArray[0]);<br />
          Int16 SYear = Convert.ToInt16(StartDateArray[2]);<br />
          //End Date<br />
          Int16 EDate = Convert.ToInt16(EndDateArray[1]);<br />
          Int16 EMonth = Convert.ToInt16(EndDateArray[0]);<br />
          Int16 EYear = Convert.ToInt16(EndDateArray[2]);<br />
        Int16  TotalDay = 0;<br />
          string strTDays=&#8221;";<br />
        Int16  NumDayInMonth =Convert.ToInt16(DateTime.DaysInMonth(SYear, SMonth));<br />
          if (SYear&lt;=EYear)<br />
          {<br />
              if (SMonth &lt;= EMonth)<br />
              {</p>
<p>                  while (SDate !=EDate &amp;&amp; SMonth!=EMonth)<br />
                  {<br />
                      if (SDate  != NumDayInMonth)<br />
                      {<br />
                         SDate  = Convert.ToInt16(SDate+1) ;<br />
                          TotalDay =Convert.ToInt16( TotalDay+1);<br />
                      }<br />
                      if (SDate  == NumDayInMonth)<br />
                      {<br />
                          SDate = 1;<br />
                          SDate  =Convert.ToInt16(SDate+1);<br />
                          SMonth =Convert.ToInt16(SMonth+1);<br />
                          TotalDay = Convert.ToInt16(TotalDay+1);<br />
                      }</p>
<p>                  }<br />
                  strTDays =Convert.ToString(TotalDay+1);</p>
<p>              }<br />
          }<br />
          return strTDays;<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

