int = MoonPhaseAngle(nDate, nTimeOfDay, nMoonDataSourceIndex)
This macro function gives the Moon's position in its phase cycle on nDate at nTimeOfDay. Here, “phase angle” means the Moon's geocentric ecliptic longitude minus the Sun's, normalized to the range 0° (inclusive) to 360° (exclusive). The reference points are 0° for new Moon, 90° for first quarter, 180° for full Moon and 270° for last quarter.
➢The function multiplies this phase-cycle angle in degrees by 10000 and truncates it to an integer from 0 to 3599999. For example, 2782548 represents 278.2548°.
•Use the local date and time of Moon data source nMoonDataSourceIndex. Supply nTimeOfDay in millionths of a day, using MillionFromHMS.
This is a geocentric longitude difference, not the full angular separation of the Moon and Sun on the sky, an illuminated percentage, or the Sun–Moon–Earth angle measured at the Moon. The observer's location does not alter the phase-cycle angle at a given instant. Use a calculated Moon data source; a data-table source returns -1.
The macro code below checks the status of the Moon and Sun on nRunDate and this information is then used in one of the best day for an activity functions (note how this function can be used to calculate the current phase of the Moon). This is an excerpt from a larger macro used for the Farmers' Almanac. GoodDayFor is an application-specific user-defined function whose implementation is not included here.
nAt2359 = MillionFromHMS(23,59,59)
nLongitude = MoonLongitudeAngle(nRunDate, nAt2359, nIdxSrcZodiac, true)
nZodiac = MoonZodiacSignOf(nRunDate, nAt2359, true, nIdxSrcZodiac) - 1
nMoonPhase = MoonPhaseOf(nRunDate, nIdxSrcPhases, true)
bNewMoon = (nMoonPhase == 1)
bFullMoon = (nMoonPhase == 5)
bIsFirstQuarterDay = (nMoonPhase == 3)
bViertel = (nMoonPhase in [3,7])
nPhase = MoonPhaseAngle(nRunDate, nAt2359, nIdxSrcPhases)
bIn1stQuarter = (nPhase in [ 0 .. 899999])
bIn2ndQuarter = (nPhase in [ 900000 .. 1799999])
bIn3rdQuarter = (nPhase in [1800000 .. 2699999])
bIn4thQuarter = (nPhase in [2700000 .. 3599999])
bIncreasingMoon = bIn1stQuarter or bIn2ndQuarter
bDecreasingMoon = bIn3rdQuarter or bIn4thQuarter
if GoodDayFor(sCurActivity)
if sResult <> ''
sResult = sResult + ', '
endif
sResult = sResult + IntToStr(DayOf(nRunDate))
endif
See also: MoonLongitudeAngle, MoonPhaseOf, MoonPhaseAndTimeOf.
Topic 179855, last updated on 12-Oct-2026