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.


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


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

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

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

=========================================================
  Loc_Date    Loc_Time  Cnst   Julian_Date_UT   Phase_Ang
============  ========  ==== =================  =========
 2025-Feb-01  00:00:00  Aqr  2460707.708333333   35.36319
 2025-Feb-02  00:00:00  Psc  2460708.708333333   48.69446
 2025-Feb-03  00:00:00  Psc  2460709.708333333   61.99859
 2025-Feb-04  00:00:00  Ari  2460710.708333333   75.22747
 2025-Feb-05  00:00:00  Ari  2460711.708333333   88.34898
 2025-Feb-06  00:00:00  Tau  2460712.708333333  101.34225
 2025-Feb-07  00:00:00  Tau  2460713.708333333  114.19160
 2025-Feb-08  00:00:00  Tau  2460714.708333333  126.88152
 2025-Feb-09  00:00:00  Gem  2460715.708333333  139.39393
 2025-Feb-10  00:00:00  Gem  2460716.708333333  151.70834
 2025-Feb-11  00:00:00  Cnc  2460717.708333333  163.80459
 2025-Feb-12  00:00:00  Leo  2460718.708333333  175.66702
 2025-Feb-13  00:00:00  Leo  2460719.708333333  187.28896
 2025-Feb-14  00:00:00  Leo  2460720.708333333  198.67637
 2025-Feb-15  00:00:00  Vir  2460721.708333333  209.85003
 2025-Feb-16  00:00:00  Vir  2460722.708333333  220.84601
 2025-Feb-17  00:00:00  Vir  2460723.708333333  231.71490
 2025-Feb-18  00:00:00  Vir  2460724.708333333  242.51992
 2025-Feb-19  00:00:00  Lib  2460725.708333333  253.33434
 2025-Feb-20  00:00:00  Lib  2460726.708333333  264.23825
 2025-Feb-21  00:00:00  Sco  2460727.708333333  275.31458
 2025-Feb-22  00:00:00  Oph  2460728.708333333  286.64410
 2025-Feb-23  00:00:00  Sgr  2460729.708333333  298.29909
 2025-Feb-24  00:00:00  Sgr  2460730.708333333  310.33564
 2025-Feb-25  00:00:00  Cap  2460731.708333333  322.78522
 2025-Feb-26  00:00:00  Cap  2460732.708333333  335.64680
 2025-Feb-27  00:00:00  Aqr  2460733.708333333  348.88200
 2025-Feb-28  00:00:00  Aqr  2460734.708333333    2.41565
 2025-Mar-01  00:00:00  Psc  2460735.708333333   16.14335

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

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