Muwatta Imam Malik Book of The Qibla, Hadith 7
Yahya related to me from Malik from Yahya ibn Said that Said ibn al-Musayyab said, "The Messenger of Allah ﷺ prayed towards the Baytal-Maqdis for sixteen months after arriving in Madina. Then the qibla was moved, two months before the battle of Badr. "
وَحَدَّثَنِي عَنْ مَالِكٍ، عَنْ يَحْيَى بْنِ سَعِيدٍ، عَنْ سَعِيدِ بْنِ الْمُسَيَّبِ، أَنَّهُ قَالَ صَلَّى رَسُولُ اللَّهِ ﷺ بَعْدَ أَنْ قَدِمَ الْمَدِينَةَ سِتَّةَ عَشَرَ شَهْرًا نَحْوَ بَيْتِ الْمَقْدِسِ ثُمَّ حُوِّلَتِ الْقِبْلَةُ قَبْلَ بَدْرٍ بِشَهْرَيْنِ .