When were the angels created? I was preparing a lesson for Sunday school and came across this passage in the teaching material:


  Where were you when I laid the foundation of the earth? Tell Me, if you have understanding, who set its measurements? Since you know. Or who stretched the line on it? 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? (Job 38:4-7)


The NIV uses "angels" instead of "sons of God" implying angels were present at the creation of the earth.

So my question is, when were the angels created, exactly?  Was it on day one of the "Creation Week"? ... Was it before the first day of Creation? (How is that possible?) ... Was it "outside of time"?

Please use Scripture to support your answer.  I am also curious whether the passage I quoted relates to the answer (do "sons of God" refer to angels), and if so, how?
Thomas Aquinas cites Psalm 148 in STh Ia 61,1 (Whether the angels have a cause of their existence?), holding that the word "they" in verse 5 refers to all of what is listed earlier in the psalm:


  Praise him, all his angels, praise him, all his host!
      3 Praise him, sun and moon, praise him, all you shining stars!
      4 Praise him, you highest heavens, and you waters above the heavens!
      5 Let them praise the name of the LORD! For he commanded and they were created


He seems to be following Augustine here. Compare City of God Book XI, ch. 9, where Augustine cites Psalm 148 and also cites a similar passage from the Prayer of Azariah Canticle of the Three Young Men in Daniel 3 (this portion of Daniel is considered apocryphal by some).

Augustine seems to take it for granted that Job 38:7 refers to the angels, and actually uses this passage as the starting-point in his argument that the creation of the angels is included in what Genesis calls the creation of light (because the angels already existed when the stars were created). I don't know what text of Job he would have had, but he quotes it thus:


  Quando facta sunt sidera, laudauerunt me uoce magna omnes angeli mei.


Literally, "when the stars were made, all my angels praised me in a loud voice". The entire (relatively brief) chapter is basically one fascinating answer to your question.