Good old dates in Javascript. So what I do is create a data object from the value of the date field. Then I add the days to the date object.
This way if you wanted to add 14 days to a date, and lets say the date was 10/22, you wouldn't be passing a date to the api of 2007-10-36 which is invalid. And the date object in JS figures this our for you.
Here is a function you can use to add N number of days to a date.
Code:
function getDateDaysAhead(apiDateField,numDaysAhead){
//seting the string value of numDaysAhead to a number numDaysAhead = new Number(numDaysAhead);
var startDate = apiDateField.split("-"); //this is in the yyyy-mm-dd format var year = startDate[0]; var mth = startDate[1]; var day = startDate[2];
var dtNewDate = new Date(year,mth,day);
var dateProposed = new Date(dtNewDate.getFullYear(),dtNewDate.getMonth() -1,dtNewDate.getDate() +numDaysAhead);
//if the Proposed date falls on a Sunday (0) or a Saturday(6), push it out by 2 days //you can take this out if you are not worried about work week. if((dateProposed.getDay() == 0) || (dateProposed.getDay() == 6)){ dateProposed = new Date(dtNewDate.getFullYear(),dtNewDate.getMonth() -1,dtNewDate.getDate()+2); }
This way if you wanted to add 14 days to a date, and lets say the date was 10/22, you wouldn't be passing a date to the api of 2007-10-36 which is invalid. And the date object in JS figures this our for you.
Here is a function you can use to add N number of days to a date.
Code:
Hope this helps you.