The exclusion is not pro-rated. You may, however, qualify for a partial exclusion if the main reason for the sale was a change in workplace location, a health issue, or an unforeseeable event.
Otherwise, you must have owned and used your home as your main home for a period aggregating at least two years out of the five years prior to its date of sale.
Under certain circumstances, you may be able to avoid paying taxes if you lived there less than 2 years. The most common is moving due to relocating for work, but see Publication 523 for details: