Earth rotates on its own axis once every 24 hours. It is this rotation gives rise to night and day on our planet (and other planets in our solar system). The rotation is due to the history of Earth's origin. A few billion (about 4.6 billion) years ago, before our solar system existed, large clouds of gas and dust existed in its place. This cloud began to collapse under its own gravity and during the process flattened into a large disk and began to rotate. The spinning of matter (gases and dust) increased and localized regions of high density were formed. These regions later emerged as planets. Many bodies began to rotate around these planets and became their moons. All the planets in our solar system have been rotating around the sun since then and also on their own respective axis.
Hope this helps.