Whoever resolves to fast only after the day has begun—for instance, one who wakes up after dawn has broken, has not eaten anything, and then decides to fast—will not have that fast count, except when the fast is voluntary. An obligatory fast, by contrast, is not established by an intention formed during the day, because the entire daytime period must be covered by fasting, and an intention cannot apply retroactively to time that has already passed.
As for supererogatory fasting, it may be entered into with an intention formed during the day. This is based on the report from ʿĀʾishah (may Allah be pleased with her): “The Prophet, peace and blessings be upon him, came to us one day and said, ‘Do you have anything [to eat]?’ We replied, ‘No.’ He said, ‘Then I am fasting.’” The hadith is recorded by all of the major compilers except al-Bukhārī. The fact that he requested food shows that he was not fasting beforehand, making the narration clear evidence that delaying the intention is permissible for a voluntary fast; with it the texts that appear to forbid such delay are restricted.
The validity of a voluntary fast begun with an intention formed during the day is conditioned on nothing contrary to fasting—such as eating or drinking—having occurred prior to that intention. If a person does something that breaks the fast before intending to fast, the fast is invalid, and there is no disagreement on this point.