Days of the Moon

Posted on Tuesday, January 04, 2005 11:09 AM by K. Latham
Whether you're a farmer, fishermen, stargazer or witch, you'll eventually need to know when the next full/new moon is.

This is some ASP code I created to calculate the days (phase) of the moon:
Function MoonClock(dtDate)
DIM strLine
DIM lngPhase
lngPhase = POM(dtDate)
IF lngPhase = 1 THEN strLine = "<B>" & clng(lngPhase) & "</B> day "
IF lngPhase <> 1 THEN strLine = "<B>" & clng(lngPhase) & "</B> days "
MoonClock = strLine
End Function

Function POM(dtDate)
DIM lngDiff
lngDiff = DATEDIFF("d",DATESERIAL(2004,12,12),dtDate)
While lngDiff > 29.5
lngDiff = lngDiff - 29.5
Wend
POM = INT(lngDiff)
End Function
How I use the above code:
It's been <% =MoonClock(NOW) %> since the last <A HREF="http://aa.usno.navy.mil/data/docs/MoonPhase.html#y<% =YEAR(NOW) %>">new moon</A>.
I am very sure there is a way better way to do this, but this is what I came up with at the time.

One problem with my code is the need to adjust the date in the POM function (Phase of Moon) This date corresponds with the New Moon. This only needs to be adjusted every once in a while (yearly?).

The Navy has a handy table to look up these dates:
  2005 PHASES OF THE MOON - UNIVERSAL TIME
  
        NEW MOON    FIRST QUARTER        FULL MOON     LAST QUARTER
  
         d  h  m          d  h  m          d  h  m          d  h  m
  
                                                     JAN.   3 17 46
  JAN.  10 12 03   JAN.  17  6 57   JAN.  25 10 32   FEB.   2  7 27
  FEB.   8 22 28   FEB.  16  0 16   FEB.  24  4 54   MAR.   3 17 36
  MAR.  10  9 10   MAR.  17 19 19   MAR.  25 20 58   APR.   2  0 50
  APR.   8 20 32   APR.  16 14 37   APR.  24 10 06   MAY    1  6 24
  MAY    8  8 45   MAY   16  8 56   MAY   23 20 18   MAY   30 11 47
  JUNE   6 21 55   JUNE  15  1 22   JUNE  22  4 14   JUNE  28 18 23
  JULY   6 12 02   JULY  14 15 20   JULY  21 11 00   JULY  28  3 19
  AUG.   5  3 05   AUG.  13  2 38   AUG.  19 17 53   AUG.  26 15 18
  SEPT.  3 18 45   SEPT. 11 11 37   SEPT. 18  2 01   SEPT. 25  6 41
  OCT.   3 10 28   OCT.  10 19 01   OCT.  17 12 14   OCT.  25  1 17
  NOV.   2  1 24   NOV.   9  1 57   NOV.  16  0 57   NOV.  23 22 11
  DEC.   1 15 01   DEC.   8  9 36   DEC.  15 16 15   DEC.  23 19 36
Just be sure to put in a new moon date that's less than today, otherwise you will get a negative number and no body wants a negative moon.

I would love to see all of your ideas on how to calculate the day of the moon. Please post a comment.