A dwelling is considered to be your main residence from the time you acquired your ownership interest in it if you moved into it as soon as practicable after that time. This would generally be the date of settlement of the purchase contract. This means that, if there is a delay in moving in because of illness or other reasonable cause, the exemption is still available from when you acquired your ownership interest in the dwelling.
If you could not move in because the dwelling was being rented to someone, you are not considered to have moved in as soon as practicable after you acquired your ownership interest.
As mentioned earlier, there is a special rule that allows you to treat more than one dwelling as your main residence for a limited time if you are changing main residences (see Moving from one main residence to another).