I would always use 'in' except in cases where you mean 'inside the boundaries of...'. Consider these two sentences:
The job had to be done in a week (it would take a week to do it)
The job had to be done within a week (completed in no more than seven days from the day the order was given).
But: The rule applied only within the school grounds (where within means inside)
And: Sorry, been interrupted. Hope this helps.