كتاب الفضائل
43  
The Book of Virtues
(33)
Chapter: How Long Did The Prophet ft Stay In Makkah And Al-Madinah?
(33)
باب كَمْ أَقَامَ النَّبِيُّ صلى الله عليه وسلم بِمَكَّةَ وَالْمَدِينَةِ ‏.‏
Sahih Muslim 2353 e

Ibn 'Abbas reported that Allah's Messenger (ﷺ) stayed in Mecca for fifteen years (after his advent as a Prophet) and he heard the voice of Gabriel and saw his radiance for seven years but did not see any visible form, and then received revelation for ten years, and he stayed in Medina for ten years.

وَحَدَّثَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ الْحَنْظَلِيُّ، أَخْبَرَنَا رَوْحٌ، حَدَّثَنَا حَمَّادُ بْنُ سَلَمَةَ، عَنْ عَمَّارِ بْنِ أَبِي عَمَّارٍ، عَنِ ابْنِ عَبَّاسٍ، قَالَ أَقَامَ رَسُولُ اللَّهِ صلى الله عليه وسلم بِمَكَّةَ خَمْسَ عَشْرَةَ سَنَةً يَسْمَعُ الصَّوْتَ وَيَرَى الضَّوْءَ سَبْعَ سِنِينَ وَلاَ يَرَى شَيْئًا وَثَمَانَ سِنِينَ يُوحَى إِلَيْهِ وَأَقَامَ بِالْمَدِينَةِ عَشْرًا ‏.‏
Reference : Sahih Muslim 2353e
In-book reference : Book 43, Hadith 162
USC-MSA web (English) reference : Book 30, Hadith 5809
  (deprecated numbering scheme)