The scientific consensus is that the Earth's moon formed four and half billion years ago. About 100 million years after the formation of the solar system, another small planet is likely to have collided with the Earth, resulting in the formation of the Moon.
The solar system was formed when a giant cloud of dust and gas condensed to create the Sun. The planets were formed from leftover material that began to orbit the sun. Shortly after the formation of the solar system, a collision between Earth and a planet approximately the size of Mars created the Moon, which remained in Earth's orbit as its only satellite and which affects several natural processes including the Earth's tidal pattern.