Q. God created angels first before humans (we know because Satan was already fallen as the serpent). But do we know why He created them? And when?

A. The word “angel” translates the Hebrew word “mal’ak” and the Greek word “aggelos“. The former means “messenger, representative, or ambassador”; the latter also means “messenger, envoy, one who is sent”. As such, we know one primary purpose God created them was to be His messenger, to communicate His will e.g.
Dan 8:16 And I heard the voice of a man between the banks of Ulai, and He called out and said, “Gabriel, give this man an understanding of the vision.”
• Mt 2:13 Now when they had gone, behold, an angel of the Lord appeared to Joseph in a dream and said, “Get up! Take the Child and His mother and flee to Egypt, and remain there until I tell you; for Herod is going to search for the Child to destroy Him.”
• Lk 1:28 And coming in, he (an angel) said to her (Mary), “Greetings, favored one! The Lord is with you.”
• Acts 5:20 “Go, stand and speak to the people in the temple the whole message of this Life.”
An angel spoke to Peter and the apostles.

Another reason God created angels was to execute His purposes, including His judgments e.g.
Ps 103:21 Bless the LORD, all you His hosts, you who serve Him, doing His will.
• 2 Sam 24:16 When the angel stretched out his hand toward Jerusalem to destroy it, the LORD relented from the calamity and said to the angel who destroyed the people, “It is enough! Now relax your hand!” And the angel of the LORD was by the threshing floor of Araunah the Jebusite.
• Mt 13:41 The Son of Man will send forth His angels, and they will gather out of His kingdom all stumbling blocks, and those who commit lawlessness,
• Jn 5:4 for an angel of the Lord went down at certain seasons into the pool and stirred up the water; whoever then first, after the stirring up of the water, stepped in was made well from whatever disease with which he was afflicted.
• Acts 12:23 And immediately an angel of the Lord struck him because he did not give God the glory, and he was eaten by worms and died.

What’s more, they were charged to watch over and serve God’s children e.g.
Ps 34:7 The angel of the LORD encamps around those who fear Him, and rescues them.
• Ps 91:11 For He will give His angels charge concerning you, to guard you in all your ways.
• Mt 18:10 See that you do not despise one of these little ones, for I say to you that their angels in heaven continually see the face of My Father who is in heaven.
• Heb 1:14 Are they not all ministering spirits, sent out to render service for the sake of those who will inherit salvation?

As to when, the Bible did not state explicitly, but there are hints:
Gen 2:1 Thus the heavens and the earth were completed, and all their hosts. The hosts refer to heavenly hosts, or angels.
• Ex 20:11 For in six days the LORD made the heavens and the earth, the sea and all that is in them, and rested on the seventh day; therefore the LORD blessed the Sabbath day and made it holy. “All that is in them” would include angels.
• Job 38:6-7 On what were its bases sunk? Or who laid its cornerstone, when the morning stars sang together and all the sons of God shouted for joy?
When God laid the cornerstone of the earth, the morning stars and the sons of God, both referring to angels, were there already to sing and praise.
So the clues point to early in the creation week, but we just can’t be sure.