When did God create the heavens and the earth?
Genesis 1 gives an account of creation. The first verse states that God created the heavens and the earth.
Genesis 1:1 In the beginning God created the heavens and the earth;
Some people want to treat this first sentence, or clause (depending on how the translation is punctuated), as a summary statement of creation. There is nothing in the text itself to warrant this. However, putting a break after the first verse makes it impossible to answer the question of when God created the heavens and the earth. It happened at some unknown time in the past, and the first day of creation starts at verse 2.
However, if we treat the first verse as the start of the first day, it simplifies everything.
Genesis 1:1 In the beginning God created the heavens and the earth;
Gen 1:2 The earth was without form, and void; and darkness was on the face of the deep. And the Spirit of God was hovering over the face of the waters.
Gen 1:3 Then God said, “Let there be light”; and there was light.
Gen 1:4 And God saw the light, that it was good; and God divided the light from the darkness.
Gen 1:5 God called the light Day, and the darkness He called Night. So the evening and the morning were the first day.
At the start of the first day of creation God created the heavens and the earth. The heavens are space and the earth’s atmosphere, which are the two physical heavens, see “What are the three heavens?” God also created the earth, but as verse 2 explains, it had no form, but was covered with water. On subsequent days God formed the dry land, vegetation, and animals. God created the sun, moon, and stars in the heavens (space) on the fourth day. The answer to the question of when God created the heavens and the earth is quite clear. He created them on the first day of the six days of creation.
For more a detailed discussion, see “How old is the earth?”