Ok, first understand the problem. Imagine (because it isn't so, but it helps) that the Earth has no tilt and moves in a perfect circle around the Sun and the Sun itself is a point of light, not a ball 1/2 a degree wide. Sunrise and sunset will be at the same time every day,
6:00 am and 6:00 pm at the equator, earlier and later as you move North or South. When you reach either Pole it will not set at all, but goes around the horizon. The function for this is the cosine of latitude, cos(90 degrees) = 0. Now we tilt the Earth, and we do so in our imagination by 90 degrees. The North pole faces the Sun on mid-summer's day, and the south pole faces the Sun 6 months later. As you know, Northern Summer is Southern Winter and vice versa. With our 90 degree tilt the Sun doesn't rise or set at the equator on mid-summer's day OR mid-winter's day, equal day and night occur mid-spring and mid-autumn.
Okay, so much for latitude and tilt, next is orbital eccentricity. We imagined that the Earth moved in a perfect circle, but it doesn't. It is closest to the Sun on or about Jan 3rd at 91,000,000 miles and furthest 6 months later at 94,000,000 miles, moving in an elliptical orbit. As we did above, we again imagine an extreme case where the Earth passes very close to our point-like Sun and then 6 months later is way out near Pluto. The orbit is almost a straight line. The Earth falls toward the Sun going faster and faster (as comets do) and then swings around the back where gravity is at its greatest, climbs away again and slows as it gets toward Pluto's orbit where it stops climbing and falls once again, just as a ball thrown straight up would do. Now, when far from the Sun the Earth turns once a day, sunset and sunrise are about the same each day, but when close to the sun we have a problem with that. The Earth turns on its axis
360 degrees in what is called a sidereal day (1 sidereal day = 23.9344696 hours) and there are 366, (not 365) sidereal days in a year.
formatting link
is when the Earth has turned not to face the sun once a day, but to face the other stars. You will notice that the night sky has different stars directly overheard between Summer and Winter. This means that when (in our imagination) the Earth passes very close by the sun, noon, when the sun is overhead, can last for 12 hours. Look at the diagram at
formatting link
you'll see why. Last and least, the Sun is NOT a point. Now... the computation of Earth's orbit is something you do NOT want to do.
formatting link
In conclusion, a look-up table is the simplest solution for you.