From blog post: Forty is a symbol
The number 40 appears in a several different places in the scriptures, almost always in the context of purging or purification. When the Lord destroyed the wicked at the time of Noah, He caused it “to rain upon the earth for forty days and forty nights.” (Genesis 7:4.) When Moses met with the Lord on the Mount, he was in the presence of the Lord “forty days and forty nights” (Exodus 24:18.) When Israel proved unprepared to inherit the promised land, the Lord left them in the wilderness for forty years. (Deuteronomy 8:2.)
Elijah was fed by an angel before being sent into the wilderness. After the meal, Elijah “went in the strength of that meat forty days and forty nights unto Horeb the mount of God.” (1 Kings 19:8.) In preparation for His ministry, the Lord likewise “fasted forty days and forty nights.” (Matthew 4:2.) That preparation culminated in angels ministering to the Him. (Matthew 4:11.)
In these examples, it is not a man volunteering or choosing to afflict his soul for forty days. The period of purification is imposed by the Lord. We do not get the choose to be purified through suffering for a period of forty days, or forty years, or any other amount of time. However, if the Lord chooses to purify a soul, and that suffering does last for forty days, you can take it as a sign that the purification was given of God.
I know people have tried to voluntarily afflict themselves for forty days. I think an effort like that shows a poor understanding of how God deals with man. We wait on Him. We submit to Him. Then He alone chooses.