Click to See Complete Forum and Search --> : Date Calculation


rmagan
05-04-2006, 12:22 PM
I am trying to take the date value (format MM/DD/YYYY) of my input field, do calclulations on it and store the calculated value in a differnt field. Sometimes I need to add 1 year to the date and sometimes 30 days. I can't seem to understand how to do the calculations on a date. Can someone show me how to add 1 year or 30 days to a field?

<input type="text" name="p_iep_team_meeting_date" size="9" maxlength="10" onBlur="calc_due_date(this)>

function calc_due_date(iep_team_date)
{
var in_date = stripCharString(iep_team_date.value," ");
var ms = Date.parse(in_date);
document.post_sped_demographic.p_iep_due_date.value = ms;
}

Charles
05-04-2006, 01:20 PM
<script type="text/javascript">
Date.prototype.plusDays = function (n) {
d = new Date (this.getTime())
d.setDate (d.getDate() + n)
return d
}

Date.prototype.plusYears = function (n) {
d = new Date (this.getTime())
d.setFullYear (d.getFullYear () + n)
return d
}

alert (new Date().plusDays (30))
</script>

rmagan
05-04-2006, 01:32 PM
Thanks, but I will be passing in the date and doing calculations on it, and storing in a new field. See my code. How would you do that?