It is permissible to observe a voluntary fast with an intention formed during the day before the sun reaches its Zenith, and it is permissible for one who is observing a voluntary fast to break his fast with no excuse, although it is better for him to complete it Sahih Muslim 1154 b
Translation
'A'isha, the Mother of the Believers (Allah be pleased with her), reported
The Apostle of Allah (ﷺ) came to me one day and said: Is there anything with you (to eat)? I said: No. Thereupon he said: I shall then be fasting. Then he came to us another day and we said: Messenger of Allah, hais has been offered to us as a gift. Thereupon he said: Show that to me; I had been fasting since morning. He then ate it.