<?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>DansNetwork.com &#187; extending the DOM</title>
	<atom:link href="http://dansnetwork.com/tag/extending-the-dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://dansnetwork.com</link>
	<description>Web Design, Javascript, CSS, and More...</description>
	<lastBuildDate>Wed, 19 May 2010 20:02:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript Date Object &#8211; Adding and Subtracting Months</title>
		<link>http://dansnetwork.com/2008/09/18/javascript-date-object-adding-and-subtracting-months/</link>
		<comments>http://dansnetwork.com/2008/09/18/javascript-date-object-adding-and-subtracting-months/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 12:05:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[extending the DOM]]></category>
		<category><![CDATA[javascript]]></category>
		<guid isPermaLink="false">http://blog.dansnetwork.com/2008/09/18/javascript-date-object-adding-and-subtracting-months/</guid>
		<description><![CDATA[There is a slight problem with the Javascript Date() Object when trying to advance to the next month or go back to the previous month. For example, if your date is set to October 31, 2008 and you add one month, you&#8217;d probably expect the new date to be November 30, 2008 because November 31st [...]]]></description>
			<content:encoded><![CDATA[<p>There is a slight problem with the Javascript Date() Object when trying to advance to the next month or go back to the previous month. For example, if your date is set to October 31, 2008 and you add one month, you&#8217;d probably expect the new date to be November 30, 2008 because November 31st doesn&#8217;t exist. This, however, isn&#8217;t the case. Javascript automatically advances your Date object to December 1st. This functionality is very useful in most situations(i.e. adding days to a date, determining the number of days in a month or if it&#8217;s a leap year), but not for adding/subtracting months. I&#8217;ve put together some functions below that extend the Date() object: <strong>nextMonth()</strong> and <strong>prevMonth()</strong> <em>See the example below for their usage and please feel free to use these in your applications.</em></p>
<p>Extends the Date Object:</p>
<pre class="brush: jscript;">
function prevMonth(){
var thisMonth = this.getMonth();
this.setMonth(thisMonth-1);
if(this.getMonth() != thisMonth-1 &amp;&amp; (this.getMonth() != 11 || (thisMonth == 11 &amp;&amp; this.getDate() == 1)))
this.setDate(0);
}
function nextMonth(){
var thisMonth = this.getMonth();
this.setMonth(thisMonth+1);
if(this.getMonth() != thisMonth+1 &amp;&amp; this.getMonth() != 0)
this.setDate(0);
}
Date.prototype.nextMonth = nextMonth;
Date.prototype.prevMonth = prevMonth;
</pre>
<p>Example of Usage:</p>
<pre class="brush: jscript;">
function getPrevMonth(){
var today = new Date(2008,9,31); //set &quot;today&quot; to October 31, 2008
today.prevMonth(); //show one month earlier -&gt; September 30, 2008 (instead of September 31, 2008 which converts to October 1st, 2008
}
function getNextMonth(){
var today = new Date(2008,9,31); //set &quot;today&quot; to October 31, 2008
today.nextMonth(); //show one month later -&gt; November 30, 2008 (instead of November 31, 2008 which converts to December 1st, 2008
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dansnetwork.com/2008/09/18/javascript-date-object-adding-and-subtracting-months/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
