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

PHP Program by Jay Tanner - 2025

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.

It is called the 'simple' lunar phase because it is geocentric and based on
the 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 purposes and
general small-scale graphical simulations.

If you wish to make a table of lunar phases for a given month, this function
can be helpful.

PhaseTable = Lunar_Phase_Table (StartDateTime, StopDateTime, StepSize,
                                TimeZone, DaySumYN, HeaderYN)


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

Time Zone       = UT-05:00       (dJDate = -0.2083333333)
Day/Summ Time   = No
Table Header    = Yes

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

===========================================================
   Loc_Date     Loc_Time  Cnst   Julian_Date_UT   Phase_Ang
==============  ========  ==== =================  =========
AD 2025-Oct-01  00:00:00  Sgr  2460949.708333333  103.85375
AD 2025-Oct-02  00:00:00  Cap  2460950.708333333  115.63857
AD 2025-Oct-03  00:00:00  Cap  2460951.708333333  127.81422
AD 2025-Oct-04  00:00:00  Aqr  2460952.708333333  140.42026
AD 2025-Oct-05  00:00:00  Aqr  2460953.708333333  153.46515
AD 2025-Oct-06  00:00:00  Psc  2460954.708333333  166.91703
AD 2025-Oct-07  00:00:00  Psc  2460955.708333333  180.69897
AD 2025-Oct-08  00:00:00  Psc  2460956.708333333  194.69256
AD 2025-Oct-09  00:00:00  Ari  2460957.708333333  208.75166
AD 2025-Oct-10  00:00:00  Tau  2460958.708333333  222.72437
AD 2025-Oct-11  00:00:00  Tau  2460959.708333333  236.47686
AD 2025-Oct-12  00:00:00  Aur  2460960.708333333  249.91140
AD 2025-Oct-13  00:00:00  Gem  2460961.708333333  262.97405
AD 2025-Oct-14  00:00:00  Gem  2460962.708333333  275.65199
AD 2025-Oct-15  00:00:00  Cnc  2460963.708333333  287.96418
AD 2025-Oct-16  00:00:00  Leo  2460964.708333333  299.94958
AD 2025-Oct-17  00:00:00  Leo  2460965.708333333  311.65641
AD 2025-Oct-18  00:00:00  Leo  2460966.708333333  323.13386
AD 2025-Oct-19  00:00:00  Vir  2460967.708333333  334.42697
AD 2025-Oct-20  00:00:00  Vir  2460968.708333333  345.57424
AD 2025-Oct-21  00:00:00  Vir  2460969.708333333  356.60771
AD 2025-Oct-22  00:00:00  Vir  2460970.708333333    7.55475
AD 2025-Oct-23  00:00:00  Lib  2460971.708333333   18.44111
AD 2025-Oct-24  00:00:00  Lib  2460972.708333333   29.29442
AD 2025-Oct-25  00:00:00  Sco  2460973.708333333   40.14768
AD 2025-Oct-26  00:00:00  Oph  2460974.708333333   51.04196
AD 2025-Oct-27  00:00:00  Sgr  2460975.708333333   62.02818
AD 2025-Oct-28  00:00:00  Sgr  2460976.708333333   73.16737
AD 2025-Oct-29  00:00:00  Cap  2460977.708333333   84.52925
AD 2025-Oct-30  00:00:00  Cap  2460978.708333333   96.18866
AD 2025-Oct-31  00:00:00  Cap  2460979.708333333  108.21940

***********************************************************
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)

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