Almost the entire solar sytem formed 4.6 billion years ago, about the same time as the solar nebula collapsed.
It is thought that a mars sized protoplanet crashed into the earth and the large debris from the planet cooled and formed the moon.
The collison happened well before the earth had any basis of life, and when it was a flaming ball of molten rock.
But this is still a theory of what happened.

Apollo moon landing missions turned up lunar rocks, that have oxygen isotope compositions which are almost the the same as the earth.
This states that the moon is at least 4 billion years old.
