Moon Dates in excel

callsidd

Board Regular
Joined
Jul 2, 2005
Messages
122
Hi,

Can anyone please guide how I can get moon dates in excel? Means whatever date I input, result show moon phase date/age?



Regards..
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You need to calculate the Paschal Full Moon date either side of the date, and interpolate how far between the two the date is.

To calculate PFM:

Code:
Public Function PFM(InputDate as Date) as Date
 
Dim FirstDig, Remain19, temp    'intermediate results    
Dim PFM as date
 
FirstDig = int(InputDate/100) 'first 2 digits of year
Remain19 = InputDate Mod 19             'remainder of year / 19
 
' calculate PFM date
temp = (FirstDig - 15) \ 2 + 202 - 11 * Remain19
 
   Select Case FirstDig
      Case 21, 24, 25, 27 To 32, 34, 35, 38
         temp = temp - 1
      Case 33, 36, 37, 39, 40
         temp = temp - 2
   End Select
   temp = temp Mod 30
 
   PFM = temp + 21
   If temp = 29 Then PFM = PFM - 1
   If (temp = 28 And Remain19 > 10) Then PFM = PFM - 1
 
End Function
 
Upvote 0
Editted: I misread the post and posted something for finding the fullm Moon before Easter.

What you need to do is find the date of a full moon (such as Saturday's). Subtract the days bwtween the date you want and that date. If you can work out the time of the fullmoon on Sat, put that into the date as well

Code:
Public Function MoonAge(InputDate As Date) As Date
 
     startDate = #3/18/2011#
     MoonAge = ((InputDate - startDate) Mod 29.5305882) / 29.5305882
 
End Function
 
 
Public Function MoonPhase(InputDate As Date) As String
 
     startDate = #3/18/2011#
 
Dim moonage%
Dim Moont
 
     Moont = (((InputDate - startDate) Mod 29.5305882) / 29.5305882) * 8
     moonage = Int(Moont)
 
     Select Case moonage
     Case 0
         MoonPhase = "New Moon"
     Case 1
         MoonPhase = "Waxing Crescent Moon"
     Case 2
         MoonPhase = "Quarter Moon"
     Case 3
         MoonPhase = "Waxing Gibbous Moon"
     Case 4
         MoonPhase = "Full Moon"
     Case 5
         MoonPhase = "Waning Gibbous Moon"
     Case 6
         MoonPhase = "Last Quarter Moon"
     Case 7
         MoonPhase = "Waning Crescent Moon"
     Case Else
         MoonPhase = "Error - Moon has plunged into the Earth"
     End Select
 
End Function
 
Upvote 0
This gives results within a half day or so from the US Naval Observatory numbers at
http://www.usno.navy.mil/USNO/astronomical-applications/data-services/phases-moon. New moon is zero, 0.5 is full moon.

Code:
Public Function MoonAge(ByVal tDate As Date) As Double
    Const a         As Double = 0.000000000102026
    Const b         As Double = 29.530588861
    Const k         As Double = 20.362955
    
    Dim NA          As Double   ' full moon number prior to tDate
    Dim NB          As Double   ' full moon number subsequent to tDate
    Dim c           As Double
    Dim tFMA        As Date
    Dim tFMB        As Date
 
    c = k - tDate + #1/1/2000#

    NA = Int((-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a))
    NB = NA + 1
 
    tFMA = a * NA ^ 2 + b * NA + k + #1/1/2000#
    tFMB = a * NB ^ 2 + b * NB + k + #1/1/2000#
 
    MoonAge = (tDate - tFMA) / (tFMB - tFMA)
    MoonAge = MoonAge + IIf(MoonAge <= 0.5, 0.5, -0.5)
End Function
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top