We sold a second home then bought another second home in same year. Can we write off non-overlapping expenses on both homes?

We owned a second home that was not our primary residence but sold it in July 2016. We then bought another home, also as a secondary residence, shortly thereafter. Can we write off expenses as long as the dates don't overlap or is one of the homes still considered a third residence for the tax year.