(33) باب كَمْ أَقَامَ النَّبِيُّ صلى الله عليه وسلم بِمَكَّةَ وَالْمَدِينَةِ .
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 2353 e
In-book reference: Book 43, Hadith 162
USC-MSA web (English) reference(deprecated numbering scheme): Book 30, Hadith 5809