Investors & landlords

Appreciate. All I am trying here is to understand the law of 1031 to save on capital gain tax. 
if I buy investment property through 1031 exchange how long I have to hold it as investment property before I can turn it into primary residence and how long I have to live in it before I can sell it to avoid the capital gain tax