No bank will give you a mortgage until you build your credit and show the bank your credit worthiness.
How long it takes you to rebuild your credit is up to you, but I can tell you one thing, it's not going to be within 2 years. 4 years at the least.
You will also need to show a steady income that will qualify you for the mortgage and the bank will also require a minimum of 20% as a down payment.

