Honestly that is the question of the ages. Sages haven't been able to answer this question nor scientists for that matter. In order to know scientifically how long it took for the earth to form, one would have to follow the steps within the scientific method. In following this method, one must be able to duplicate the occurrence in order to make a scientific theory.
If one goes to Scripture, well then that is another story all together and if you believe in a Creator God, and in Intelligent Design one would say that earth and all it contains was created in six days and on the seventh day God rested and saw that it was good. :)