Comparing dates Java Script
<p>I have the following scenario that I am strugling to code.</p>

<p>I have a valuation date that is a string that is chosen by a user from a calander popup.  What I need to do is take that date and pass it into a function that works outs a second date depending on the value of that date.  If the first date is more than 7 days from the first day of the month use the first day of the month else use the last day of the month.  This needs to happen in client side as this date need to be displayed after they have chosen the first date.</p>

<p>SO far I have the below:</p>

<pre><code>Function CompareDate()
{ var date1 = document.getElementById("textbox1");
var x = new date();
var year = x.getYear();
var day = x.getDay();
var thisMonthFirstDay = new Date(year, month,1)
var thisMonthLastDate = ....
var 1day = 1000*60*60*24
var date1_ms = recdate
var date2ms =  thisMonthFirstDay.gettime()
if(Math.round(difference_ms/1day) &gt; 7
{var textbox = document,getelementbyid("textbox2");
textbox.value = texbox.value + thisMonthLastDate 

}
else
{
textbox.value = texbox.value + thisMonthFirstDay }
}
</code></pre>

<p>Any examples of how this can be done would be greatly appeciated.
Cheers</p>
