Sayyiduna Ibn Abbas (may Allah be pleased with them both) said: The Messenger of Allah (peace and blessings be upon him) was turned (in prayer) from facing Bayt al-Maqdis to the Qiblah, and so he (peace and blessings be upon him) prayed facing the Ka'bah in Rajab, seventeen months after his arrival in Madinah.
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 12445