When was the moon formed in relation to the earth?
At about the same time.
Our current understanding of the formation of the Earth, is that it first was formed by acretion. Then the proto-Earth was struck by another proto-planet about the size of Mars. Not straight on, since that would have destroyed both masses, but something of a glancing blow. That collision added some material to the proto-Earth and threw enough material into orbit to eventually coales into the Moon. This all happened around 4.5 Billion years ago.
Now the Sun formed about 4.6 Billion years ago, so we have 50-100 Million years for these proto-planets to form and the collision to occur. This is called the Giant Impact theory. It is the most accepted theory (though not the only one).
Here's a link to a short video if you want to see: