<p>If you provide <code>0</code> as the <code>dayValue</code> in <code>Date.setFullYear</code> you get the last day of the previous month:</p>

<pre><code>d = new Date(); d.setFullYear(2008, 11, 0); //  Sun Nov 30 2008
</code></pre>

<p>There is reference to this behaviour at <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/setFullYear" rel="noreferrer">mozilla</a>. Is this a reliable cross-browser feature or should I look at alternative methods?</p>

I would use an intermediate date with the first day of the next month, and return the date from the previous day:
```
```
int_d = new Date(2008, 11+1,1);
d = new Date(int_d - 1);
```
```