פּירוש אויף שמות 34:28

וַֽיְהִי־שָׁ֣ם עִם־יְהוָ֗ה אַרְבָּעִ֥ים יוֹם֙ וְאַרְבָּעִ֣ים לַ֔יְלָה לֶ֚חֶם לֹ֣א אָכַ֔ל וּמַ֖יִם לֹ֣א שָׁתָ֑ה וַיִּכְתֹּ֣ב עַל־הַלֻּחֹ֗ת אֵ֚ת דִּבְרֵ֣י הַבְּרִ֔ית עֲשֶׂ֖רֶת הַדְּבָרִֽים׃

און ער איז דאָרטן געװען מיט גאָט פֿערציק טעג און פֿערציק נעכט; קײן ברױט האָט ער ניט געגעסן, און קײן װאַסער האָט ער ניט געטרונקען. און ער האָט אױפֿגעשריבן אױף די לוחות די װערטער פֿון דעם בונד, די צען געבאָט.

Chizkuni

ויהי שם עם ה, “he remained there with the Lord, etc.” this was the third time that Moses spent 40 days on the Mountain. He ascended at dawn on the twenty ninth day of Av, and remained there until dawn of the tenth day of Tishrey, better known as Yom Hakippurim. If you were to ask how Moses could tell day and night from each other, seeing that in the celestial regions day and night are all the same, seeing that we have a verse in Daniel 2,22 ונהורא עמיה שריה, “and light dwells with Him?” We also a verse in Psalms,גם חשך לא יחשיך ממך ולילה כיום יאיר כחשכת אורך :139,12“darkness is not dark for You; night is as light as day.”We need to answer that when G-d taught Moses the written Torah, he knew that it was daytime down on earth. When He taught him the oral Torah, he knew that it was night on earth at that time. Furthermore, when he observed the moon and the stars bowing down to the Lord, he knew that it must be daytime on earth, as these celestial bodies had to perform their duties on earth at night. When he observed the sun paying its respect to G-d, he knew that it was night on earth, as during the daylight hours the sun had to perform its duties on earth.
פֿרעגט אַ רבֿBookmarkShareCopy

Ramban

AND HE WAS THERE WITH THE ETERNAL FORTY DAYS AND FORTY NIGHTS… AND HE WROTE UPON THE TABLETS THE WORDS OF THE COVENANT, THE TEN WORDS. The verse is stating that Moses was on top of the mountain for forty days and forty nights, and he wrote there upon the Tablets. And in the opinion of our Rabbis542Shemoth Rabbah 47:12. the meaning of the verse is that Moses was there with G-d for forty days and forty nights,543From the first of Ellul to the tenth of Tishri, which is the Day of Atonement. during which time He wrote on the Tablets the words of this second covenant. But he had stayed there for another forty days544From the nineteenth of Tammuz to the twenty-ninth of Ab. prior to these to pray for all his requests, as is narrated in the section beginning, See, Thou sayest unto me: Bring up this people;545Above, 33:12. and with reference to these days it is said in the Book of Deuteronomy, So I fell down before the Eternal the forty days and forty nights that I fell down; because the Eternal had said He would destroy you.546Deuteronomy 9:25. Here, however, Scripture did not explain how many days were the duration of this period of supplication and prayer, for it is known that it was from the time he went up to the mountain until he came down to hew the second Tablets.547This was on the first day of Ellul (see Ramban above, 33:7). Having hewn the Tablets, he went up to the mountain and stayed until the tenth of Tishri. From this we learn that the forty-day period of prayer preceded it, which brings it to the days between the nineteenth of Tammuz and the twenty-ninth of Ab. But it said that the matter of the second Tablets was like that of the first in every respect — the writing of G-d, and the number of days he stood before G-d, so that he should not think that he had already learned the Torah during the first time, and that therefore it would not be necessary for him to stay there many days.
פֿרעגט אַ רבֿBookmarkShareCopy

Sforno

'ויהי שם עם ה, his third and final 40 day stay there..
פֿרעגט אַ רבֿBookmarkShareCopy