you can use this to substract or add days to a date: d.setDate(d.getDate() + parseInt(flag, 10));