Update: 2nd March 2019:
Moon Phase =
The result is a real number in the range 0 to 1, where 0 means the moon is new, 0.5 means it is full, etc.
Max error ~ 60 minutes
Median error ~19 minutes
original post continues below:
I recently looked into how to calculate the phase of the moon in order to add an “age of the moon” indicator and a changing moon image display.
as in …
After reading posts on this forum and doing some online research, I came up with the following:
age of the moon ( in days ) ~= ((((#DNOW#-585122000)/86400000))%29.530588)
This gives the age of the moon in days ( assuming a fixed lunar synodic period of 29.53 days ).
The number 585122000 is the time in milliseconds between GMT: Thursday, January 1, 1970 12:00:00 AM ( the start date for the #DNOW# tag ) and what would have been the approximate date/time for the first new moon after that date if the synodic period was constant. This number was obtained empirically by recursively solving for the “new moon date/time” in order to minimise the RMS value of the difference between the full moon dates/times predicted by the above formula and the dates/times for the full moon over the next 10 years from published tables.
This formula results in the following variation between predicted and actual date/time of the full moon ( in days ):
with an RMS value of about 0.3 days.
Choosing an actual historic new moon date as the offset in the equation, instead of a calculated value, will, in general, produce a significant offset to the above curve, and thus exacerbating the already quite large “error” between the average synodic period based prediction and the actual moon phase.
If you want to convert between the “Unix timestamp” ( given by #DNOW# ) and human readable date/time you can use the online tools at:
for example, 585122000 is equivalent to GMT: Wednesday, January 7, 1970 6:32:02 PM
( versus the actual new moon time of 596100000 or 7 Jan 9:35 pm; using this time would add an additional constant offset/error to the prediction formula of around 3hrs ).
Note that the timestamp entry in the tool is in seconds ( so, eg. 585122000 / 1000 )