The Prophet ﷺ remained in Mecca for ten years during which the Quran was revealed to him, and ten years in Medina.
لبث النبي ﷺ بمكة عشر سنين ينزل عليه القرآن، وبالمدينة عشرا.
Bukhari narrated it in the Virtues of the Quran (4978, 4979) through the route of Shayban, from Yahya, from Abu Salama, who said, Ayesha and Ibn Abbas told me, and then he related it.As for his saying, "ten years," the accepted view is that he ﷺ lived sixty-three years. Whatever contradicts this can be explained either as disregarding the fraction of years, or as rounding up the fraction of months. As for this hadith and the one before it, they can be reconciled by saying that he ﷺ was commissioned as a prophet at the turn of forty, so the period of revelation coming through dreams lasted six months, until the angel came down to him in the month of Ramadan without interruption. Then the revelation paused, and afterward it came in continuous succession, so the period of its continuous succession in Makkah lasted ten years without interruption.