It is narrated from Sayyiduna Hudhayfah bin Asid (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: "The angel comes to the drop of fluid forty or forty-five nights after it has settled in the womb, and says: O Lord, is it wretched or fortunate? Allah, the Mighty and Majestic, tells him and the two of them write it down. Is it male or female? Allah tells him and the two of them write it down, and they write down its afflictions, its traces, its provision and its term of life. Then the scroll is rolled up; nothing is added to it and nothing is taken away."
Hadith Referenceالمعجم الكبير للطبراني / باب الحاء / 3026