Estimated about 4 billion years ago, about half a billion years after the formation of the Earth. It used to be its own little planet about the size of Mars, it slammed into Earth at an angle, tilting the Earth on its axis, giving us our 4 seasons. The impact liquified both planets, the smaller one was captured by Earth's gravity and became our moon.
The earth formed about 4.5 - 4.6 billion years ago along with the moon forming about 10 million years later, both through a process called "aggregation". We know this by several methods of dating minerals found on earth and in the rocks brought back from the moon by the Apollo Astronauts.