Sayyiduna Sa'id bin al-Musayyib (may Allah have mercy on him) used to say that the Messenger of Allah (peace and blessings be upon him) prayed facing Bayt al-Maqdis for sixteen months after coming to Madinah, then two months before the Battle of Badr, the Qiblah was changed.
Hadith Referenceالسنن المأثورة / ما جاء في الجمع بين الصلاتين في المطر / 36
Hadith Takhrijمؤطا مالك ، القبلة، باب ماجاء في القبلة، رقم : 460 مرسلاً؛ ابن سعد في الطبقات : 242/1؛ البيهقي في السنن الكبرى : 3/2 وفى معرفة السنن والآثار له : 482/1، رقم 656۔