Praise be to Allah.
In the case of a supererogatory fast that is not done for a specific reason, it is not stipulated that the intention should be formed from the night before; rather if a person decides to fast during the day, then he fasts until sunset, that is acceptable, so long as he has not done anything that breaks the fast since dawn broke.
But in the case of a supererogatory fast that is done for a specific reason, it is essential to form the intention from the night before (i.e., from before dawn).
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked:
Does fasting six days of Shawwaal and the day of ‘Arafaah come under the same ruling as obligatory fasts, in that it is stipulated that the intention should be formed from the night before? Or does it come under the same ruling as general supererogatory fasts; it is permissible for the individual to intend to fast that day, even if that is halfway through the day? Will the reward of one who decides to fast halfway through the day be like the reward of the one who eats sahoor and fasts from the beginning to the end of the day?
Yes, it is permissible to intend to observe a supererogatory fast partway through the day, on condition that one has not done any action that breaks the fast before that. For example, if a person eats after dawn has broken, then during the day he decides to fast, we would say to him in that case: Your fast is not valid, because you ate something. But if he had not eaten anything from the time dawn broke, and he did not do anything that breaks the fast, then he decided during the day to observe a supererogatory fast, then we say: this is acceptable, because it is narrated that the Prophet (blessings and peace of Allah be upon him) did that.
The reward is only from the time the intention was formed, because the Prophet (blessings and peace of Allah be upon him) said: “Actions are but by intentions.” So whatever came before the intention was formed will have no reward recorded for it, but reward will be recorded for what comes after it.
If the reward is connected to the day’s fast, then he has not fasted the entire day; rather he has fasted part of the day with the intention. Based on that, if someone were to get up after dawn breaks and not eat anything, then halfway through the day he decided to fast on the basis that it was one of the six days, then he fasted five more days after that, then he will have fasted five and a half days. If he formed the intention to fast after one quarter of the day had passed, then he will have fasted five and three quarters days, because actions are judged by intentions, and the hadith says: “Whoever fasts Ramadan then follows it with six days of Shawwaal.”
In that case we say to this brother: you have not attained the reward for fasting the six days, because you did not fast six full days. The same may be said with regard to the day of ‘Arafah. But if the fast is a general supererogatory fast (not connected to a specific reason), then it is valid and he will be rewarded from the time he formed the intention only.
End quote from Liqa’ al-Baab al-Maftooh (55/21)
He also said:
If the virtue of the fast is connected to a particular day, such as fasting on Mondays and Thursdays, fasting the ayyaam al-beed (the 13th, 14th and 15th of the Hijri month), fasting three days of every month, and he forms the intention (to fast) during the day, then he does not attain the reward of that day.
So for example, if he fasts on a Monday but forms the intention to fast during the day, he will not earn the same reward as one who fasted from the beginning of the day, because it cannot truly be said of him that he fasted (all of) Monday.
Similarly, if a person wakes up not fasting, then he is told that today is the thirteenth of the (Hijri) month, and it is the first of al-ayyaam al-beed, so he said: Then I am fasting, he will not earn the reward of al-ayyaam al-beed, because he has not fasted an entire day.
End quote from ash-Sharh al-Mumti‘ (6/360)
For more information, please see the answer to question no. 21819
And Allah knows best.