Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) says: As long as a person has not eaten or drunk anything, he has the choice.
Imam al-Shafi'i (may Allah have mercy on him) says: They (meaning the people of Iraq) do not hold this view; rather, they say that unless he makes the intention to fast before the sun passes its zenith, his fast will not be valid. But we say that in a voluntary fast he may make the intention whenever he wishes.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصيام / 7921