After the Messenger of Allah ﷺ arrived in Madinah, he prayed toward Bayt al-Maqdis for sixteen months, and then the qibla was changed two months before Badr.
و حدثني عن مالك عن يحيى بن سعيد
صلى رسول الله ﷺ بعد أن قدم المدينة ستة عشر شهرا نحو بيت المقدس ثم حولت القبلة قبل بدر بشهرين