[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1335
  • Last Modified:


What is the algorithm for determining sunrise/sunset, moonrise, and twilight based on the date and the latitude and longitude?
1 Solution
This is a complicated one but here goes....
This formula was first intended for a four bit microprocessor, so I'm sure there may be a better way to figure it.

First, have the user enter their Latitude, and whether they are North or South Latitude.  Let this be 'L'.  Have the user enter today's sunrise time.

Each month has a different formula.  Basicaly you figure out how much change there is in each month, then spread that change over the month.

NOTE:  The formulas below contain numbers in parenthesis.  If the answer from within the parenthesis is negative, set it to zero.  It will not be used if less than zero.
Sunset                               sunrise
JAN (L/2 + 13)+(L-45)+(L-49)=JMin    sub 22 then invert sign
FEB (L-8)+(L-44)+(L-55)=FMin         add 2 then invert sign
Mar (L-10)+(L-40)+(L-55)=MMin        add 18 "     "      "
Apr (L-11)+(L-42)+(L-55)=AMin        add 14 then invert sign
May (L-10)+(L-47)+(L-53)=MyMin       Sub 1   "     "     "
Jun (L/8 + 6) + (L-52) + (L-65)=JeMin  Subt 11  "  "  "
July (JMin-16) then invert sign      (JMin-10) no sign change
Aug (FMin+9) then invert sign        (FMIn-3) "   "    "
Sep (MMin + 18) then invert sign     (MMin -3)  "   "    "
Oct (AMin+14) then invert sign       (AMin+2)  "    "     "
Nov (MyMin-6) then invert sign       (Mymin+4) "    "     "
Dec (JeMIn -19) then invert sign     (JeMIn+10)  "  "  "

Example  Latitude = 10N  sunset time for Jan 1 = 6:34am  sunset time for Jan 1 = 6:53 pm
JMim = (10/2 + 13) + (10-45) + (10-49).  (10-45) anbd (10-49) end up negative, so set them to zero
JMin = 18.  this is the total number of minutes change in January.  So at the end of January the sun will set 18 minutes later or at 7:11pm

Note: If latitude = South, then invert the sign on each result. So in January at latitude 10S the JMin = -18.
Latitude is restricted from 10<= L <= 70

My hands are tired now, I must rest.....


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now