To get both the husband and wife $250K cap gains exclusion on a home sale, must you be married at the time of the sale or just married by the time taxes are filed?

For example, lets say I am single and sell my house in June 2019, I get married in December of 2019 and then file my taxes for 2019 as married filing jointly, can we get both $250K capital gains exclusions totaling $500K?