Deductions & credits

If you don't qualify for the hardship exception then it is all or nothing.  You owe tax on the entire gain if you move in less than 2 years, and you owe tax on the gain if you moved out 3.5 years ago so only get credit for 1.5 of the past 5 years.