The Shulchan Aruch · Orach Chayim
אורח חיים רס״חOrach Chayim 268
Siman 268 of 697 in Orach Chayim — 13 se'ifim
הלכות שבתLaws of Shabbat· siman 268
Se’if 1א׳
אוֹמֵר וַיְכֻלּוּ בִּתְפִלַּת עַרְבִית.
The laws governing One who errs in the Shabbos prayers, 13 Seifim: We say Vayechulu during Ma'ariv.
Se’if 2ב׳
אִם טָעָה וְהִתְחִיל תְּפִלַּת הַחֹל, גּוֹמֵר אוֹתָהּ בְּרָכָה שֶׁנִּזְכַּר בָּהּ שֶׁטָּעָה וּמַתְחִיל שֶׁל שַׁבָּת, לָא שְׁנָא נִזְכַּר בְּבִרְכַּת אַתָּה חוֹנֵן לֹא שְׁנָא נִזְכַּר בִּבְרָכָה אַחַת מִשְּׁאָר הַבְּרָכוֹת, בֵּין בְּעַרְבִית בֵּין בְּשַׁחֲרִית, מוּסָף וּמִנְחָה. וְיֵשׁ אוֹמְרִים דִּבְמוּסָף פּוֹסֵק אֲפִלּוּ בְּאֶמְצַע בְּרָכָה.
If one errs and begins to say the weekday prayer (Amidah), one finishes that blessing wherein he realized he erred and then begins the Shabbat prayer. It does not matter if he remembers in the blessing 'Atah Chonen' or if he remembers in one of the other blessings, whether in the Evening Prayer or the Morning prayer, Musaf or Minchah. There are those who say that in Musaf, one pauses even in the middle of the blessing.
Se’if 3ג׳
אִם הָיָה סָבוּר שֶׁהוּא חֹל וְהִתְחִיל אַדַּעְתָּא דְּחֹל וּמִיָּד כְּשֶׁאָמַר תֵּבַת אַתָּה נִזְכַּר קֹדֶם שֶׁאָמַר חוֹנֵן, הֲוָה לֵיהּ הִתְחִיל בְּשֶׁל חֹל וְגוֹמֵר אוֹתָהּ בְּרָכָה; אֲבָל אִם הָיָה יוֹדֵעַ שֶׁהוּא שַׁבָּת, וְשֶׁלֹּא בְּכַוָּנָה הִתְחִיל תֵּבַת אַתָּה, אֲפִלּוּ אִם הוּא בִּתְפִלַּת שַׁחֲרִית שֶׁאֵינָהּ פּוֹתַחַת בְּאַתָּה אֵינוֹ גּוֹמֵר בִּרְכַּת אַתָּה חוֹנֵן דְּחַשְׁבִינָן לֵיהּ כְּטָעָה בִּתְפִלַּת שַׁבָּת בֵּין זוֹ לְזוֹ. הַגָּה: דַּהֲרֵי יָכוֹל לוֹמַר אַתָּה קִדַּשְׁתָּ אוֹ אַתָּה אֶחָד (תְּרוּמַת הַדֶּשֶׁן סִימָן י"ד).
If one is certain that it is a weekday and he begins the weekday amidah, and immediately when he says the first letter he realizes, before he says 'Chonen' that he is saying the weekday prayer, he finishes that prayer. However, if he knew that it is Shabbat and without the appropriate intention begins the word 'atah', even if he is in the morning prayer where we do not open with 'atah', he does not finish the blessing 'atah chonen' because it is considered as an error in the prayer of Shabbat, whether this or that. Rema: Because he can say 'atah kidashta' or 'atah echad' (Terumat Hadeshen Siman 14).
Shulchan Aruch, Orach Chayim — Torat Emet 363 edition, via Sefaria — public domain
English: Sefaria Community Translation — CC0