Aaagh!
Yet another post perpetuating the myths about passport validity.
Assuming you have a British (or other EU) passport, you have an automatic right to travel to, and live in, any EU country. The Spanish authorities are obliged, by law, to admit you even if you arrive with just one minute left on your passport. (Theoretically, if you could find an alternative way of proving your EU citizenship, they'd be obliged to let you in without any passport). The date you leave is irrelevant because there is no obligation upon you ever to leave the country. (You could remain in Spain for the rest of your life if you wanted to. Obviously it's wisest to ensure that your passport is still valid on departure, since it could cause problems getting back into the UK).
The information in my post is confirmed by reading the 'Note' under 'Passports' in Dennis's link.
Chris