The Qur’an did not mention the period, but indicated that he did not get out immediately.
A caravan was on its way to Egypt. Usually convoys draw water from wells on their trips in order to drink. When one of the people put down his bucket to draw water, Yusuf pbuh hung onto the bucket. When he drew the bucket up, he saw Yusuf pbuh. And this is how Yusuf pbuh survived the well.
(And there came some travellers, and they sent their water-boy who let down his bucket into the well. He cried out, “Oh, what a great find! Here is a boy!” And they took him secretly ˹to be sold˺ as merchandise, but Allah is All-Knowing of what they did. They ˹later˺ sold him for a cheap price, just a few silver coins—only wanting to get rid of him.) Yusuf 12:19-20
لم يذكر القرآن تلك المدة و إنما أشار إلى أن خروجه لم يكن مباشرأ
جاءت مارة في الطريق متوجهة إلى بلاد مصر، و على عادة القوافل تستقي الماء من الآبار في الطريق. أنزل من كان في مقدمة القافلة الدلو فتعلق به يوسف فلما أخرجه فإذا به يرى غلاما فنجي يوسف من غياهب البئر.
(وَجَاءَتْ سَيَّارَةٌ فَأَرْسَلُوا وَارِدَهُمْ فَأَدْلَىٰ دَلْوَهُ ۖ قَالَ يَا بُشْرَىٰ هَـٰذَا غُلَامٌ ۚ وَأَسَرُّوهُ بِضَاعَةً ۚ وَاللَّـهُ عَلِيمٌ بِمَا يَعْمَلُونَ ﴿﴾ وَشَرَوْهُ بِثَمَنٍ بَخْسٍ دَرَاهِمَ مَعْدُودَةٍ وَكَانُوا فِيهِ مِنَ الزَّاهِدِينَ )
يوسف 12: 19 -20