The corresponding code can be found at http://www.esrl.noaa.gov/gmd/grad/solcalc/
You need longitude, latitude and date. It would be useful to indicate whether you want an answer in local or global time. The corrections necessary to obtain true accuracy (and the definition that you use for "sunrise" and "sunset") all play a huge role in the efficiency of the calculation.
If you just want to know "approximately" when the sun is on the same level with the horizon "on the assumption of a spherical earth, circular orbit around the Sun and without atmospheric distortion" - then all shooting approaches something completely controllable. But if you want a real answer, you need to work out about 600 lines of script on this website.
For approximations you can see this earlier answer
Floris
source share