JQuery Date Problem - Adding 1 Year

JQuery Date Problem - Adding 1 Year

Hi,

I am using a jQuery datepicker to select a contract start date, and from this i want it to automatically calculate the contract end date which should be 1 year from the start date. I am using the following code to try todo this:

  1. $('#dtecontractstart').change(function() {
  2. // Get the date from the #dtecontractstart
  3. sContractStart = $('#dtecontractstart').val();
  4. // Split the string on the /
  5. var arr = sContractStart.split('/');
  6. // Change the array so the format is yyyy,mm,dd
  7. var newdate = arr[2]+","+arr[1]+","+arr[0];
  8. var myDate = new Date(newdate);
  9. var ContractEndDay = myDate.getDate()- 1
  10. if (ContractEndDay<10) ContractEndDay="0"+ContractEndDay;
  11. var ContractEndMonth = myDate.getMonth()+ 1
  12. if (ContractEndMonth<10) ContractEndMonth="0"+ContractEndMonth;
  13. var ContractEndYear = myDate.getFullYear()+ 1
  14. ContractEndDate = ContractEndDay + "/" + ContractEndMonth + "/" + ContractEndYear;
  15. $('#dtecontractend').val(ContractEndDate);
  16. });
This seems to work fine if the date slected is 02/03/2011, as it uses the above and brings back 01/03/2011.... 

However if i select 01/03/2011, it should return 28/02/2011, but i get 00/03/2012...

Any ideas why, also i am new to jQuery and have built the above, is the code correct or is there a much easier way of doing this?

Thanks in advance,
D