If you look at Genesis 1 you will see that the sun, moon and stars are only created on the fourth day, but there are days before then "there was evening, and there was morning -- the first day." Although the component for morning and evening (the sun) is not yet created, God already had the concepts firmly in mind.
There is an orderliness about the creation account:
Creation is not random, circumstantial or chaotic.
The picture that Gen 1 gives us is that God is firmly in charge, that God delights in His creation and that He is working with a plan.
Also woven into the orderliness of creation is DELIGHT.
God is enjoying His creation. It is good and it gives Him joy.
Again, we are not getting hung up on the HOW in the sense of the of creation (I think our brains are actually too small to grasp the detail). We are more concerned in WHO created and that His divine and sovereign qualities are beautifully reflected in the account of creation. We see God's creativity, power and internal-integrity portrayed as orderliness. The HOW we can look at is the of creation and that style is orderly, joyful and excellent.
We are not here by mistake or accident. We are the end result of a carefully thought through plan where the Creator joyfully and systematically made a world that was good!