Skip to main content

Prayer times, part 2: where is the sun today?

· 38 min read
Rizki Rakasiwi
Muslimtify maintainer

In part 1 we saw that every prayer time is a sentence about the sun. The sun declines. A shadow reaches a length. The twilight fades. A white line spreads along the horizon.

To turn those sentences into a number, you need to know where the sun is. Not roughly, but exactly: on this date, in this city, at this minute. That is what this part is about. By the end you will have a small program that tells you two facts about the sun for any date, and you will use them to work out the moment the sun is highest over your head today, which you can check with a stick.

This is part 2 of a series

Part 1 covered what the Quran, the Sunnah and the early generations say about prayer times. This part builds the one piece of astronomy everything else depends on. Part 3 uses it to compute Dhuhr, sunrise and Maghrib. The full series is under the prayer time calculation tag.

From words to numbers​

The scholars of the first centuries left exact definitions in words. Turning them into numbers for a given city on a given day was the work of a different kind of scholar.

In ninth century Baghdad, al-Khwarizmi compiled a zij, a book of tables giving the position of the sun, moon and planets for any date, with instructions for using them. Al-Battani, a generation later, measured the length of the year and the tilt of the earth's axis so precisely that his numbers were still being quoted in Europe seven hundred years on. By the thirteenth century the great mosques of Cairo and Damascus employed a muwaqqit, a timekeeper whose job was to apply these tables to the prayer times of his own city. The most famous of them, Ibn al-Shatir, was muwaqqit of the Umayyad Mosque in Damascus and built a sundial for it in 1371 that computed the prayer times directly from the shadow.

A zij was a big book because the astronomers had to tabulate everything by hand. We are going to write a very small zij, about thirty lines, that gives us the two numbers the muwaqqit needed for the sun.

The two numbers​

Think about what a prayer time actually needs to know.

Dhuhr needs to know when the sun is at its highest over your city, which is not 12:00 on the clock. Fajr, Maghrib and Isha need to know when the sun is a certain distance below your horizon. Asr needs to know how high the sun climbs today, because that sets the length of the shortest shadow.

All of those depend on where you are, which we handle in part 3, and on two things that change with the date and are the same for everyone on earth:

  1. How far north or south of the equator the sun stands today. Astronomers call it the sun's declination.
  2. How far ahead of or behind the clock the sun is running today. Astronomers call it the equation of time.

Get these two from the date, add your latitude and longitude, and everything else is geometry.

Declination: the sun's latitude​

The earth's axis is tilted by about 23.44° compared to its path around the sun. As the earth goes around, that tilt makes the sun appear to drift north and south over the year. On 21 June the sun stands directly over the Tropic of Cancer, 23.44° north. On 21 December it stands over the Tropic of Capricorn, 23.44° south. On the two equinoxes in March and September it is directly over the equator.

SunN21 Junesun over 23.44° NN21 Decembersun over 23.44° SN21 Marchsun over the equatorN23 Septembersun over the equatorThe axis always leans the same way, so the sun lights the north more in June and the south more in December.
The tilt of the earth's axis stays fixed while the earth goes around the sun. That is the whole reason the sun's declination swings north and south through the year.

The declination is the latitude the sun is "over" today. It runs from +23.44° to -23.44° and back every year.

Why it matters to you: Jakarta is at about 6.2° south. Twice a year, in early March and again in early October, the declination is exactly -6.2°, and at noon on those days the sun is straight overhead and a vertical stick casts no shadow at all. On every other day the noon shadow has some length, and that length is set by the gap between your latitude and today's declination. That is the stick from part 1, and it is how Asr will be computed in part 5.

-23.44-100+10+23.44JanFebMarAprMayJunJulAugSepOctNovDecdeclination, degreesJakarta, 6.2° south21 Jun, over the Tropic of Cancer21 Dec, over the Tropic of Capricorn5 Mar10 Oct
The sun's declination through 2026, computed with the code below. Where the curve crosses Jakarta's latitude the noon sun is straight overhead and a stick has no shadow.

Equation of time: the sun runs fast and slow​

Here is something that surprises most people. If you set a sundial to show exactly 12:00 at the moment the sun is highest on one day, it will be wrong on most other days of the year, by up to about 16 minutes.

The sun is not a perfect clock. The earth's orbit is slightly oval, so it moves faster in January and slower in July. And because the axis is tilted, the sun's eastward drift against the stars is not even across the year. Together these make the real sun run ahead of a perfect clock for part of the year and behind it for the rest. The difference is the equation of time. In early November the sun is about 16 minutes early. In mid February it is about 14 minutes late. Four times a year it is on time.

-15-10-50+5+10+15JanFebMarAprMayJunJulAugSepOctNovDecequation of time, minutes3 Nov, 16.4 min early11 Feb, 14.2 min late17 Oct, +14.6
How far the real sun runs ahead of (positive) or behind (negative) a perfect clock through 2026. The curve crosses zero four times a year.

Every prayer time inherits this. If your app ignored the equation of time, Dhuhr would be off by a quarter of an hour in some months.

Counting days​

Astronomy formulas do not want a month and a day. They want a single number: how many days have passed since some fixed starting point. The starting point almost everyone uses now is noon UTC on 1 January 2000, written J2000.0.

Astronomers get to that count through the Julian day, a continuous count of days running since 4713 BC. The Julian day of J2000.0 is 2451545.0. So the number we want is:

d = julian_day(date) - 2451545.0

Converting a calendar date to a Julian day takes a handful of integer tricks to account for the uneven months and leap years. The function below is the standard one from Jean Meeus's Astronomical Algorithms. You do not need to understand it. You need to know that it turns 17 October 2026 into 2461330.5, and that it works for every date after October 1582.

The recipe​

With d in hand, this is the whole calculation. It comes from the Astronomical Almanac, the yearly reference published by the US and UK naval observatories, and it is accurate to about one sixtieth of a degree between 1950 and 2050. That is far more precision than a prayer timetable rounded to the minute can use. It is also, line for line, the formula inside libmuslim, the library that computes Muslimtify's times. What you write here is what the app runs.

All angles are in degrees. The mod 360 steps just keep the angles in the 0 to 360 range.

g = 357.529 + 0.98560028 * d mean anomaly: how far around its orbit the earth is
q = 280.459 + 0.98564736 * d mean longitude: where the sun would be if the orbit were a circle
L = q + 1.915 * sin(g) + 0.020 * sin(2g) true longitude: the correction for the oval orbit
e = 23.439 - 0.00000036 * d tilt of the earth's axis, shrinking very slowly

declination = asin( sin(e) * sin(L) )
right ascension = atan2( cos(e) * sin(L), cos(L) ) / 15 in hours
equation of time = q / 15 - right ascension in hours

Read the two lines with g and q first. Both are just "a starting angle plus a fixed amount per day". The 0.9856 is 360° divided by 365.25 days, the sun's average progress per day. The L line is the oval orbit correction, and it is where the "fast and slow" comes from. The e line is the tilt.

The last three lines convert that position into the two numbers we want. The declination is the sun's latitude. The right ascension is the sun's position measured eastward in hours, the way a star chart does it. The equation of time is the gap between where the sun would be on a perfect clock, q / 15, and where it really is.

Where the numbers come from​

None of the constants are magic. Each one is a measurement of the earth's orbit, and there are only four kinds.

ConstantWhat it isHow to check it
357.529Mean anomaly at J2000.0: degrees travelled since the last perihelion, the earth's closest approach to the sun2.471° short of a full lap, at 0.9856°/day, is 2.5 days. Perihelion in 2000 fell on 4 January.
280.459Mean longitude at J2000.0: the sun's position along its yearly path, measured from the March equinox point270° is the December solstice. 10.46° past it is 10.6 days, which lands on 1 January.
0.98564736Degrees per day of mean longitude360 / 365.2422, the tropical year from equinox to equinox
0.98560028Degrees per day of mean anomaly360 / 365.2596, the anomalistic year from perihelion to perihelion
1.915, 0.020Correction for the oval orbit, in degreesFrom the orbit's eccentricity e = 0.01671: 2e and (5/4)e² in radians, converted to degrees
23.439Tilt of the earth's axis at J2000.023° 26′ 21.4″, measured
0.00000036Decrease of the tilt per day46.8 arcseconds per century, from the pull of the other planets
2451545.0Julian day of J2000.0Noon UTC on 1 January 2000
15Degrees per hourThe earth turns 360° in 24 hours

The two rates differ in the fifth decimal because the perihelion point itself creeps forward, about one degree every 58 years, so a lap from perihelion to perihelion takes 25 minutes longer than a lap from equinox to equinox.

The 1.915 deserves one more sentence, because it is the only piece of real physics in the block. A planet on an oval orbit moves fastest when it is closest to the sun. Kepler worked out the correction for that, and for a nearly circular orbit it expands as 2e sin(g) + (5/4)e² sin(2g) with e the eccentricity. Put in e = 0.01671, convert from radians to degrees, and you get 1.915 sin(g) + 0.020 sin(2g). The next term would be about 0.0003°, which is why the Almanac stops at two.

The full solar model behind the Astronomical Almanac has hundreds of terms: the pull of the moon, the pull of Jupiter, and so on. These four lines are what remains after throwing all of that away and keeping only what is needed to stay within a minute of arc for a century. For a timetable rounded to the minute, that is everything.

The code​

Here is the recipe in code, plus a solar_noon function that uses the equation of time to find when the sun is highest by your local clock. Pick your language. The tab you choose is remembered across the whole series.

import math

def julian_day(year, month, day):
if month <= 2:
year -= 1
month += 12
a = year // 100
b = 2 - a + a // 4
return math.floor(365.25 * (year + 4716)) + math.floor(30.6001 * (month + 1)) + day + b - 1524.5

def sun_position(year, month, day):
d = julian_day(year, month, day) - 2451545.0 # days since J2000.0

g = math.radians((357.529 + 0.98560028 * d) % 360) # mean anomaly
q = (280.459 + 0.98564736 * d) % 360 # mean longitude, degrees
L = math.radians((q + 1.915 * math.sin(g) + 0.020 * math.sin(2 * g)) % 360) # ecliptic longitude
e = math.radians(23.439 - 0.00000036 * d) # tilt of the earth's axis

declination = math.degrees(math.asin(math.sin(e) * math.sin(L)))
right_ascension = math.degrees(math.atan2(math.cos(e) * math.sin(L), math.cos(L))) / 15 # hours
equation_of_time = (q / 15 - right_ascension + 12) % 24 - 12 # hours, kept near zero
return declination, equation_of_time * 60 # degrees, minutes

def solar_noon(year, month, day, longitude, timezone):
_, eqt = sun_position(year, month, day)
return 12 + timezone - longitude / 15 - eqt / 60 # local clock hours

if __name__ == "__main__":
dec, eqt = sun_position(2026, 10, 17)
print(f"declination {dec:.2f} deg, equation of time {eqt:.1f} min")
noon = solar_noon(2026, 10, 17, 106.8456, 7) # Jakarta, WIB
h = int(noon); m = (noon - h) * 60
print(f"solar noon in Jakarta {h:02d}:{m:04.1f}")

One line deserves a comment: (q / 15 - right_ascension + 12) % 24 - 12. The raw difference can come out as, say, 23.76 hours when it means "0.24 hours early", because right ascension wraps around at 24. Adding 12, taking the remainder, and subtracting 12 again folds it back into the range from -12 to +12, which keeps the result near zero where it belongs.

Solar noon​

The solar_noon function is the first prayer-shaped number in the series, so it is worth reading slowly.

noon = 12 + timezone - longitude / 15 - equation_of_time / 60

Start at 12:00. The earth turns 15° every hour, so a city 106.8456° east of Greenwich sees the sun at its peak 7 hours and 7.4 minutes before Greenwich does, hence - longitude / 15. But Jakarta's clocks are set to UTC+7, a round 7 hours, so we add the timezone back. That leaves the sun peaking at 11:52.6 by the Jakarta clock if the sun were a perfect clock. It is not. On 17 October it is running 14.6 minutes early, so we subtract that too.

11:3011:3511:4011:4511:5011:5512:00longitude, −7.4 minequation of time, −14.6 min12:00 clock noon11:52.611:38.1 solar noon
How 12:00 becomes 11:38 in Jakarta on 17 October 2026. Two corrections, one for where you are and one for the date.

Check your work​

Run the program. For 17 October 2026 you should see:

declination -9.17 deg, equation of time 14.6 min
solar noon in Jakarta 11:38.1

A declination of -9.17° means the sun is standing over a point 9.17° south of the equator today, a little south of Jakarta, heading toward its southern limit in December. An equation of time of +14.6 minutes means the sun is running almost a quarter of an hour ahead of the clock.

Now check it against something you did not write. The NOAA solar calculator at gml.noaa.gov/grad/solcalc uses a more detailed version of the same astronomy. Enter Jakarta's coordinates and the date, and compare its "Equation of Time", "Solar Declination" and "Solar Noon". They should match ours to within a tenth of a minute and a hundredth of a degree.

Then check it against the sky. At 11:38 on 17 October, a vertical stick in Jakarta casts its shortest shadow of the day, pointing almost due south. If you want to feel what the muwaqqit felt, go outside and watch it.

Finally, open the Kemenag timetable for Jakarta and look at Dhuhr for the same date. It says 11:41, not 11:38. That gap is not an error. Kemenag adds two minutes of ihtiyat to every prayer and then rounds up to the next whole minute, so 11:38.1 becomes 11:40.1 and then 11:41. The precaution is the practical form of the hadith of Uqbah in part 1, which forbids praying while the sun still stands at its peak. Part 3 is where we add it.

A note on precision​

The code evaluates the sun's position at the start of the day in UTC and uses that for the whole day. The declination changes by at most 0.4° a day, which is harmless for solar noon but can shift a twilight time by about a minute at high latitudes. The production algorithm in libmuslim recomputes the sun's position at the moment of each prayer. We will do the same from part 3 on, once we have a first estimate to refine.

What to carry into part 3​

From a date alone, two numbers: where the sun stands north or south, and how far the sun is ahead of or behind the clock. From the second one, plus your longitude, the moment the sun is highest over your city.

Part 3 brings in your latitude. With it, the declination tells us how high the sun gets at noon and, more importantly for prayer, at what time it crosses the horizon on the way up and on the way down. That gives us sunrise, which ends Fajr, and sunset, which is Maghrib. It also gives us the tool that part 4 will point below the horizon to find the twilight angles.