It is narrated from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) stayed in Makkah for fifteen years: for seven years he heard the voice and saw the light but saw nothing (else), and for eight years revelation came to him; and he (peace and blessings be upon him) stayed in Madinah for ten years.
In the narration of Hajjaj bin Minhal: For seven years he saw the light and heard the voice, and for eight years revelation came to him, and he (peace and blessings be upon him) stayed in Madinah for ten years.
Imam Ahmad (may Allah have mercy on him) said: Al-Hasan held a similar view regarding how long revelation came to the Prophet (peace and blessings be upon him) in Makkah. On this breakdown, the Islam of Sayyiduna Ali (may Allah be pleased with him) came after those seven years, that is, after revelation came to the Prophet (peace and blessings be upon him), so his stay in Makkah after revelation was eight years. Then, on the view of those who say that Sayyiduna Ali (may Allah be pleased with him) was martyred at sixty-three, at the end of forty years from the emigration of the Messenger of Allah (peace and blessings be upon him), he was fifteen years old when he became Muslim, as we have narrated from al-Hasan al-Basri (may Allah have mercy on him). However, the well-known reports about the Prophet's (peace and blessings be upon him) stay in Makkah after revelation indicate more than that. And Allah knows best.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب اللقطة / 12166