كتاب القدر
46  
The Book of Destiny
(1)
Chapter: How The Human Being Is Created, In His Mother's Womb, And His Provision, Lifespan And Deeds Are Written Down, And His Misery and Happiness
(1)
بَاب كَيْفِيَّةِ خَلْقِ الْآدَمِيِّ فِي بَطْنِ أُمِّهِ وَكِتَابَةِ رِزْقِهِ وَأَجَلِهِ وَعَمَلِهِ وَشَقَاوَتِهِ وَسَعَادَتِهِ
Sahih Muslim 2643 b

This hadith has been reported on the authority of A'mash with the same chain of transmitters and in the hadith transmitted on the authority of Waki' (the words are):

" The creation of any one of you is like this that (semen) is collected in the womb of the mother for forty nights," and in the hadith transmitted on the authority of Shu'ba (the words are):" Forty nights and forty days." And in the hadith transmitted on the authority of Jarir and 'Isa (the words are):" Forty days."
حَدَّثَنَا عُثْمَانُ بْنُ أَبِي شَيْبَةَ، وَإِسْحَاقُ بْنُ إِبْرَاهِيمَ، كِلاَهُمَا عَنْ جَرِيرِ بْنِ عَبْدِ، الْحَمِيدِ ح وَحَدَّثَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ، أَخْبَرَنَا عِيسَى بْنُ يُونُسَ، ح وَحَدَّثَنِي أَبُو سَعِيدٍ، الأَشَجُّ حَدَّثَنَا وَكِيعٌ، ح وَحَدَّثَنَاهُ عُبَيْدُ اللَّهِ بْنُ مُعَاذٍ، حَدَّثَنَا أَبِي، حَدَّثَنَا شُعْبَةُ بْنُ الْحَجَّاجِ، كُلُّهُمْ عَنِ الأَعْمَشِ، بِهَذَا الإِسْنَادِ ‏.‏ قَالَ فِي حَدِيثِ وَكِيعٍ ‏"‏ إِنَّ خَلْقَ أَحَدِكُمْ يُجْمَعُ فِي بَطْنِ أُمِّهِ أَرْبَعِينَ لَيْلَةً ‏"‏ ‏.‏ وَقَالَ فِي حَدِيثِ مُعَاذٍ عَنْ شُعْبَةَ ‏"‏ أَرْبَعِينَ لَيْلَةً أَرْبَعِينَ يَوْمًا ‏"‏ ‏.‏ وَأَمَّا فِي حَدِيثِ جَرِيرٍ وَعِيسَى ‏"‏ أَرْبَعِينَ يَوْمًا ‏"‏ ‏.‏
Reference : Sahih Muslim 2643b
In-book reference : Book 46, Hadith 2
USC-MSA web (English) reference : Book 33, Hadith 6391
  (deprecated numbering scheme)