A day is simply a time frame in this dimension. All time, including everything, is created by God. Soon enough after God created the heavens and the earth, God created the sun so we could easily tell time for when He created man on the sixth day.
Basically, the sun needed to be there so man, in God's image, could tell time in some way. Just because the sun wasn't there originally doesn't mean there was no days- it just means the earth was not fit for man.
Man was created on the last day for this purpose- so everything could be given to man that was necessary for life and for survival. God created us in His image, so since God created us and gave us the breath of life, so must we use His creations here in this world, such as the sun, to survive in this dimension.
Hope this helped.