If someone goes to sleep before the time of ṣubḥ prayers in the month of Ramadan – or on any day which he assigned for keeping an obligatory (wājib) fast – without making the intention to fast, and he wakes up before midday (ẓuhr)[1] and makes the intention to fast, his fast will be valid.
However, if he wakes up after ẓuhr, he must, as a precautionary measure, abstain [from the eight things that invalidate a fast] for the rest of the day with a general intention of attaining proximity to Allah (qaṣd al‑qurbah al‑muṭlaqah) [i.e. with the intention of attaining proximity to Allah without specifying any particulars about the fast], and he must also keep a qaḍāʾ fast for it [i.e. he must make up a fast for it after the month of Ramadan].