Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moon Phase Function

Status
Not open for further replies.

JHHPavel

Technical User
Jul 18, 2003
29
US
Does anyone know of a source for an Access function which returns the phase of the Moon for a given date? Something that I can download or cut-and-paste into a module would be ideal.

The function should be something like

MoonPhase([date]) = p

where the value returned, p, would be a continuous and periodic numeric value with:
p= 0 for new moon,
p= +0.5 for waxing half moon,
p= 1.0 for full moon,
p= -0.5 for a waning half moon.

This would have to assume that the time of the moon phase measurement is standard, like Noon each day.

The reason for this lunacy is that I'd like to check the correlation of emergency room visit levels, surgical outcomes, etc., to moon phase. Not an official project, just something fun to do during the slow times here at the office. I tried something like this a few years ago, building a moon-phase table with start and end dates for the different quarters over a year, but it would be easier and more accurate to have a continuous phase function.

Paul



 
I programmed a function which has an average accuracy of about 5 hours in 2003 and 2004. The average lunar month between New Moons in those years is 29.55498 days. I simply start with the New Moon at 3:23 PM EST on January 2, 2003, and find where along the cycle a given date falls. Then some math trickery gives the values I wanted.

This does not work well outside of these two years. I tried my birthdate in 1947, which was a Full Moon, and got 0.12, which would indicate only a thick crescent. A universal function is on the drawing board.

Paul

Function MoonPhase(datCheckDate) As Double

' Comments : Returns the value of the Moon phase at Midnight for the date input
' as a numeric value between -1 and 1, where:
' New Moon = 0
' Waxing Half Moon = + 0.5
' Full Moon = 1 or -1
' Waning Half Moon = - 0.5
' Waxing values are positive, waning are negative.
' The absolute value is the portion of the Moon visible.
' Average accuracy about 5 hours in 2003 & 2004.


Dim datFixDate As Date
Dim dblInterval As Double
Dim dblPhaseLevel As Double
Dim dblPhaseValue As Double

datFixDate = #1/2/2003 3:23:00 PM#
dblInterval = datCheckDate - datFixDate
dblPhaseLevel = (dblInterval / 29.55498) - Int((dblInterval / 29.55498))

If dblPhaseLevel <= 0.5 Then dblPhaseValue = (dblPhaseLevel / 0.5) Else dblPhaseValue = ((dblPhaseLevel - 1) / 0.5)


MoonPhase = dblPhaseValue


End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top