Make your request as soon as possible. Ideally, you should apply at least three months before the start of your study program in Spain.