It is narrated from Sa'id bin al-Musayyib (may Allah have mercy on him) that he said: I heard Sa'd (may Allah be pleased with him) say that after coming to Madinah, the Messenger of Allah (peace and blessings be upon him) kept praying facing Bayt al-Maqdis for sixteen months; then, two months before the Battle of Badr, he (peace and blessings be upon him) began to face al-Masjid al-Haram.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2194