User Tools

Site Tools


mmbasic:phase_of_the_moon_for_given_date

Phase of the Moon for given date

Shows the Phase of the moon as an integer from 0 to 7.

Inspired by the first algorithm on this page (unable to find a credit - do you know different?) and first published on The Back Shed here.

Provide the day, month and year as separate integers.

Syntax: =MoonPhase(dd,mm,yyyy)

Examples: Print MoonPhase(1,1,2000) z=MoonPhase(24,12,2019)

Function MoonPhase(d As Integer,m As Integer,y As Integer) As Integer
	'calculates the moon phase (0-7), accurate to 1 segment.
	'0 => new moon, 4 => full moon, 7= last part of third quarter (before new)
	Local Float j
	If m<3 Then y=y-1:m=m+12
	m=m+1
	j=(((365.25*y)+(30.6*m)+d)-694039.09)/29.53    'total days divided by the moon cycle
	MoonPhase=Fix((j-Int(j))*8) Mod 7
End Function
mmbasic/phase_of_the_moon_for_given_date.txt · Last modified: 2024/01/19 09:30 by 127.0.0.1