Genesis chapter 1 and chapter 2 give different accounts of this.
Genesis 1-- In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.... And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.
(After this, on the 6th day-man was created.)
Genesis 2--These are the generations of the heavens and of the earth when they were created, in the day that the LORD God made the earth and the heavens,
And every plant of the field before it was in the earth, and every herb of the field before it grew: for the LORD God had not caused it to rain upon the earth, and there was not a man to till the ground.
But there went up a mist from the earth, and watered the whole face of the ground.
And the LORD God formed man of the dust of the ground, and breathed into his nostrils the breath of life; and man became a living soul.
There are some who believe that Moses took two different accounts and combined them which is why it seems different from chapter 1 to chapter 2.
In the end, if you blend the two, then earth was created first (ground, dirt) and then water second. In fact, in chapter 2, it appears that first the ground was created, then seeds were planted, and then the earth was watered--much like we would make a garden.