How would i make a dynamic skybox?

I want to make a skybox of which at day, the sun is visible etc, but at night, the moon is visible with the stars.

I think the default sky does this, no?

Yes, Im aware it does. But i was wondering how i could make it from scratch.