The question of how the earth creates night and day plagued civilization for generations, leading to the creation of many theories, such as the Greek idea that a giant chariot of fire was passing by the earth during the day. Despite these claims, modern physics and astrology has figured out why the earth has a night and day, and exactly what creates this phenomenon. Along with orbiting around the sun, the earth also rotates, from east to west, around its own central axis, with each cycle of rotation taking 24 hours. This is due to earth's formation early in the existence of our solar system, where the gravity of earth pulled in other nearby objects, causing spinning of earth to occur as more and more collisions with these nearby objects happened. Because of this spinning, only half of the earth faces the sun at any given time (day) while the other half is facing away from the sun (night). As earth rotates around its axis, day shifts to night and vice-versa based on any one location's orientation relative to the sun. Earth's rotation around its axis is also the reason why the sun rises in the east and sets in the west everyday!
Hope this helps!