View PHP Source Code 
******************************************************************************
SIMPLE LUNAR PHASE ANGLE TABLE FUNCTION DEMO
Built around the NASA/JPL Horizons API

PHP Program by Jay Tanner - 2026

This program is based on a custom function to generate a simple lunar phase
table over a given range from a single date to multiple dates spanning any
general interval at any given time step size.

This demo program generates a table of the simple geocentric lunar phase
angles for each date of the current month at 00:00:00 UTC on each date.

It is called the 'simple' lunar phase because it is geocentric and based on
the simple difference between  the ecliptical longitudes of the moon and sun
at the same moment and  excludes the  tiny effects of librations, but still
results in a good enough lunar phase approximation  for most practical pur-
poses and general small-scale graphical simulations.

-----------------
CALLING TEMPLATE:

PhaseTable = Lunar_Phase_Table (StartDateTimeStr, StopDateTimeStr, StepSize,
                                TimeZone, DaySumYN, HeaderYN)


*********************************************************
Geocentric Lunar Phase Table

Time Zone       = UT+00:00       (dJDate = +0.0000000000)
Day/Summ Time   = No
Table Header    = Yes

START Date/Time = 2026-May-01  00:00:00   (Standard Time)
STOP  Date/Time = 2026-May-31  00:00:00
Step Size       = 1 day

=========================================================
  Loc_Date    Loc_Time  Cnst   Julian_Date_UT   Phase_Ang
============  ========  ==== =================  =========
 2026-May-01  00:00:00  Vir  2461161.500000000  171.88739
 2026-May-02  00:00:00  Lib  2461162.500000000  183.06980
 2026-May-03  00:00:00  Lib  2461163.500000000  194.14179
 2026-May-04  00:00:00  Sco  2461164.500000000  205.12281
 2026-May-05  00:00:00  Oph  2461165.500000000  216.03932
 2026-May-06  00:00:00  Sgr  2461166.500000000  226.92794
 2026-May-07  00:00:00  Sgr  2461167.500000000  237.83734
 2026-May-08  00:00:00  Sgr  2461168.500000000  248.82867
 2026-May-09  00:00:00  Cap  2461169.500000000  259.97429
 2026-May-10  00:00:00  Cap  2461170.500000000  271.35479
 2026-May-11  00:00:00  Aqr  2461171.500000000  283.05372
 2026-May-12  00:00:00  Aqr  2461172.500000000  295.14941
 2026-May-13  00:00:00  Psc  2461173.500000000  307.70355
 2026-May-14  00:00:00  Psc  2461174.500000000  320.74674
 2026-May-15  00:00:00  Psc  2461175.500000000  334.26321
 2026-May-16  00:00:00  Ari  2461176.500000000  348.17978
 2026-May-17  00:00:00  Tau  2461177.500000000    2.36567
 2026-May-18  00:00:00  Tau  2461178.500000000   16.64817
 2026-May-19  00:00:00  Tau  2461179.500000000   30.84231
 2026-May-20  00:00:00  Gem  2461180.500000000   44.78471
 2026-May-21  00:00:00  Cnc  2461181.500000000   58.35911
 2026-May-22  00:00:00  Cnc  2461182.500000000   71.50607
 2026-May-23  00:00:00  Leo  2461183.500000000   84.21800
 2026-May-24  00:00:00  Leo  2461184.500000000   96.52552
 2026-May-25  00:00:00  Leo  2461185.500000000  108.48179
 2026-May-26  00:00:00  Vir  2461186.500000000  120.14896
 2026-May-27  00:00:00  Vir  2461187.500000000  131.58828
 2026-May-28  00:00:00  Vir  2461188.500000000  142.85405
 2026-May-29  00:00:00  Lib  2461189.500000000  153.99084
 2026-May-30  00:00:00  Lib  2461190.500000000  165.03348
 2026-May-31  00:00:00  Sco  2461191.500000000  176.00907

*********************************************************
Table to help visualize the lunar phase angles:

PhaseAng       Description
--------    -----------------
    0°      New Moon
   45       Waxing Crescent
   90       First Quarter
  135       Waxing Gibbous
  180       Full Moon
  225       Waning Gibbous
  270       Last Quarter
  315       Waning Crescent
 360/0      New Moon

******************************************************************************
To compute the simple  geocentric lunar phase angle (0 to 360 deg)  based on
the ecliptical longitudes of the moon and sun at the same moment also in the
the range from 0 to 360 degrees:

Let:
PhaseAng = Simple lunar phase angle (0 to 360 deg) based on the
           difference between the ecliptical longitudes.

Given:
Lm = Geocentric ecliptical longitude of the moon (0 to 360 deg).
Ls = Geocentric ecliptical longitude of the sun  (0 to 360 deg).

Then, the simple phase angle may be found
by one of the following simple algorithms:

----------------------------------------
w = 360 - Lm + Ls

if (w > 360) then w = w - 360

PhaseAng = 360 - w

----------------------------------------
Or, the alternate equivalent:

w = 360 - Lm + Ls

PhaseAng = 360 − (w −= (w > 360)? 360:0)

******************************************************************************