I am using the following function to add a number of days to a given date input (format: yyyy-mm-dd).
This works fine but does not add leading zeros when needed, e.g. it returns 2013-11-1 instead of 2013-11-01 which is what I need.
What would be the best / shortest way here to format the output as yyyy-mm-dd - jQuery would work too ?
function calcTargetDate()
{
var timeFrame = 7;
var targetDate = new Date( document.getElementById('date1').value );
targetDate.setDate( targetDate.getDate() + parseInt(timeFrame) );
document.getElementById('date2').value = ( targetDate.getFullYear() + '-' + (targetDate.getMonth() + 1) + '-' + targetDate.getDate() );
}
Many thanks in advance for any help with this, Tim