If you don't care about the time component, you can use .getDate()
and .setDate()
to just set the date part.
So to set your end date to 2 weeks after your start date, do something like this:
function GetEndDate(startDate){ var endDate = new Date(startDate.getTime()); endDate.setDate(endDate.getDate()+14); return endDate;}
To return the difference (in days) between two dates, do this:
function GetDateDiff(startDate, endDate){ return endDate.getDate() - startDate.getDate();}
Finally, let's modify the first function so it can take the value returned by 2nd as a parameter:
function GetEndDate(startDate, days){ var endDate = new Date(startDate.getTime()); endDate.setDate(endDate.getDate() + days); return endDate;}