Several years: the exact number is not mentioned. However the Quran mentions a few years. (Several is usually used for a number between 3 and 9).
(And he said to the one whom he knew to be saved: “Mention me to your lord (i.e. your king, so as to get me out of the prison).” But Shaitan (Satan) made him forget to mention it to his Lord [or Satan made [(Yusuf (Yusuf pbuh)] to forget the remembrance of his Lord (Allah) as to ask for His Help, instead of others]. So [Yusuf (Yusuf pbuh)] stayed in prison a few (more) years.}[ Yusuf 12 :42]
ليس مثبت عدده السنين الذي مكث يوسف عليه السلام في السجن بل قال تعالى : بِضْعَ سِنِينَ و البضع يطلق على العدد من 3 إلى 9 سنوات.
(وَقَالَ لِلَّذِي ظَنَّ أَنَّهُ نَاجٍ مِّنْهُمَا ٱذْكُرْنِي عِندَ رَبِّكَ فَأَنْسَاهُ ٱلشَّيْطَانُ ذِكْرَ رَبِّهِ فَلَبِثَ فِي ٱلسِّجْنِ بِضْعَ سِنِينَ)
يوسف 12: 42