Sahih al-Bukhari, Book 91, Hadith 11 (Bukhari 6734)

Narrated Abu Huraira:

Allah's Messenger (ﷺ) said, "If I stayed in prison as long as Joseph stayed and then the messenger came, I would respond to his call (to go out of the prison) ."