When the intention should be formed
What is more important than fasting is forming the intention. Muslims are obliged to form the intention and it must be formed before dawn. If the fasting is voluntary it is acceptable to form it during the day.
When the intention should be formed
A person who fasts must intend to fast, for the intention is a rukn of fasting
:as the Prophet (peace be upon him) says
‘Actions are but by intention.’
Every person shall have but that which he has intended.’ In obligatory fasting, such as the fasting in Ramadan, atonement for some misdeed, compensatory fasting or pledged fasting, the intention should be formed during the night, before the break of dawn even by seconds.
:The Prophet (peace be upon him) says
‘A person who has not intended to fast before dawn renders his fast invalid.’
Related by Abu Dawud, hadith No. 2,454; al-Tirmidhi, hadith No. 733; al-Nassa’i, hadith No. 2,331; Ibn Majah, hadith No. 1,700; al-Darimi, hadith 1,740; al-Daraqutni, hadith No. 2,214
If during the day, having not eaten or drunk anything since dawn, a person forms the intention to fast that day, it will be acceptable only if that fasting is voluntary.
:A’ishah reports
‘The Prophet (peace be upon him) came in one day and asked: “Have you got anything (to eat)?” We said: “No.” He said: Then, I am fasting.’
Related by Muslim, hadith No. 1,154
On the other hand, obligatory fasting cannot be started with an intention formed during the day. The intention in obligatory fasting must be formed during the night, before dawn. It is sufficient to form the intention on the start of Ramadan for the whole month providing he doesn’t miss a day in between.