As a general rule, a non-resident can drive a foreign registered vehicle in Spain for up to six months in a calendar year. However for a Spanish resident, it's just 30 days from the date the vehicle first entered the country. In all cases the vehicle needs to be fully legal in the country of current registration.