Deductions & credits

First of all, forget about the new house.  That  doesn't matter for anything.  It's simply when you sell the first house.  Then you look back 5 years from the date of sale.   If you owned and lived in it for 2 years of the last  5 years.  Any 2 years, doesn't have to be 2 years in a row.  Just any 720 days.