This psalm is titled A Prayer of Moses the man of God. Some commentators think this was not the same famous and familiar Moses, but the evidence is much stronger for believing that this was indeed the great leader of Israel. This is the only song of Moses in the psalms, but there are two other songs in the Pentateuch (Exodus 15 and Deuteronomy 32), as well as the blessing of the tribes of Israel in Deuteronomy 33.
If we connect it with any particular time in the life of Moses, the best suggestion is the time described in Numbers 20. “The historical setting is probably best understood by the incidents recorded in Numbers 20:
(1) The death of Miriam, Moses’ sister;
(2) The sin of Moses in striking the rock in the wilderness, which kept him from entering the Promised Land;
(3) The death of Aaron, Moses’ brother.” (James Montgomery Boice)
Moses writes; “So teach us to number our days.” When Moses considered the frail nature of humanity and the righteous judgment of God, it made him ask God for the wisdom to understand the shortness of life.
Collect for Psalm 90: Eternal Father of our mortal race; in Jesus Christ your grace has come upon us. For his sake, prosper the work of our hands until he returns to gladden our hearts forever. -5 October 2021
 Collect for Psalm 90, For All the Saints, A Prayer Book For and By the Church, Vol. IV © 1996 The American Lutheran Publicity Bureau, Delhi, NY