If, for example, someone keeps a fast with the intention of the first day of the month of Ramadan and afterwards he realises that it was the second or third of the month, his fast is valid.
Ruling 1537.* If someone who makes the intention before the time of ṣubḥ prayers to fast the next day but unwillingly becomes unconscious, and during the day he regains consciousness, then based on obligatory precaution, he must complete the fast of that day; and if he does not complete it, he must keep a qaḍāʾ fast for it.
If he becomes unconscious willingly (for example, in order to have an operation, he consents to a doctor making him unconscious), the obligatory precaution is that he must complete the fast of that day and keep a qaḍāʾ fast for it as well.