what do you mean technically less than two years. It has to be a full 24 months, to the day.
There is an exception if you are required to sell the home for unforeseen circumstances.
Unforeseen circumstances are such things as:
man made disasters
change in financial circumstances such that you can no longer pay the mortgage and still afford basic necessities.
change in job such that you are on unemployment
change in job requiring you to relocate and relocation is beyond the safe harbor miles.
In the unforeseen circumstances situation, then you may take an apportioned amount of the maximum capital gains exclusion. this is called a reduced capital gains exclusion.
There is no roll over of the primary home.
If you roll the firs home into a new rental unit, you can defer capital gains by what is called a like kind exchange. To be a like kind exchange you have to have designated the exchange prior to closing, and you have to use an exchange agent. You have only six months form the sale to complete the exchange.
The catch 22 is, you can not like kind exchange a primary residence.
AND you do not technically avoid capital gains tax, you defer it to another day in the future.