Javascript - Previous month computation from a current date
<p>I have a below JS where I get the max date that is user allowed to enter from a backend script:</p>

<pre><code>var max_date = new Date(pdate + " " + ptime);
</code></pre>

<p>where pdate and ptime is fetched from a script.</p>

<p>Now I need to set the min date as 1 month less than max_date</p>

<pre><code>if (max_date.getMonth() == 0)
subtractyear = 1;
var min_date = new Date(Date.UTC(max_date.getFullYear() - subtractyear,max_date.getMonth() - 1,max_date.getDate(),max_date.getHours(),0,0));
</code></pre>

<p>My issue is that if max_date is March 31 - then will the min_date be rolled over to Feb 28 or Feb 29 or Feb 31 or Feb 30?</p>

<p>If the date formed is an incorrect date - say Feb 30 how can I rectify this?</p>
