Page 1 of 2
Moon Phase Date webtags
Posted: Sat 17 Aug 2024 2:12 pm
by WERPNST8
Would it be possible to create webtags for the date of each moon phase? I have been changing the moon phase dates on my website manually each month for years.
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 5:25 pm
by De Hout
I don’t know if it is possible for Mark to program that feature, so let’s wait for his answer.
But if it can’t be done, and your web server has PHP enabled, I can create a PHP code for you that calculates the dates for the next 4 moon phases. This code can be implemented on your website. (You’ve given me an excellent idea for my own website, so I’m going to implement it right away.

)
Can you post your website URL, so I can already check what the output of your edited moon phases looks like?
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 5:57 pm
by Dador
There is already a <#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 7:39 pm
by De Hout
Dador wrote: ↑Sat 17 Aug 2024 5:57 pm
There is already a
<#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
True for the actual phase. But I assume (I might be wrong) he's asking for the dates of the 4 next moonphases (new moon, first quarter, full moon, last quarter).
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 9:01 pm
by WERPNST8
I would use the .php script if you develop it. That would be great. Here is the link to my astronomy page of the site.
https://www.nittanylaneweather.info/wx7.html
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 9:03 pm
by WERPNST8
Dador wrote: ↑Sat 17 Aug 2024 5:57 pm
There is already a
<#moonphase> webtag that displays the phases of the moon.
Unless you have something else in mind.
I am looking for the date for each of the next 4 phases, not just the phase.
Re: Moon Phase Date webtags
Posted: Sat 17 Aug 2024 9:37 pm
by griffo42
This has already been programmed by Ken True and shown on his website Saratoga-weather.org/almanac/sun/moon/sky/almanac and is part of his templates which are available for download from there.
Re: Moon Phase Date webtags
Posted: Sun 18 Aug 2024 8:01 am
by Weerhaas
Re: Moon Phase Date webtags
Posted: Sun 18 Aug 2024 12:47 pm
by Weerhaas
<?php
// UTC date and time
date_default_timezone_set('UTC');
$numberYear = date("Y")-2023;
$numberMonth = date("n");
// The average duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);
// Last quarter 4 Jan 2024 03:30
$lastQuarter2024 = strtotime("2024-01-04 03:30");
$lQ = ($lastQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateLastQuarter2024 = date('d-m-Y', $lQ);
echo "Last quarter : ".$dateLastQuarter2024;echo "<br>";
// New moon 11 Jan 2024 11:57
$newMoon2024 = strtotime("2024-01-11 11:57");
$nM = ($newMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateNewMoon = date('d-m-Y', $nM);
echo "New moon : ".$dateNewMoon;echo "<br>";
// First quarter 18 Jan 2024 03:52
$firstQuarter2024 = strtotime("2024-01-18 03:52");
$fQ = ($firstQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFirstQuarter = date('d-m-Y', $fQ);
echo "First quarter : ".$dateFirstQuarter;echo "<br>";
// Full moon 25 Jan 2024 17:54
$fullMoon2024 = strtotime("2024-01-25 17:54");
$fM = ($fullMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFullMoon = date('d-m-Y', $fM);
echo "Full moon : ".$dateFullMoon;echo "<br>";
?>
Re: Moon Phase Date webtags
Posted: Sun 18 Aug 2024 7:46 pm
by AndyKF650
Hi there
Thanks for the inspiration and code for the moon phase calculators. I have combined the two pieces of code and added them to my website. A real thought provoker to get me thinking in .php code again.
Code: Select all
// Moon phase calculator 18 August 2024
<?php
// UTC date and time
date_default_timezone_set('Europe/Jersey');
$numberYear = date("Y")-2023;
$numberMonth = date("n");
// The average duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);
echo "<h2>Current Moon Phases</h2>"; echo "<br>";
// Last quarter 4 Jan 2024 03:30
$lastQuarter2024 = strtotime("2024-01-04 03:30");
$lQ = ($lastQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateLastQuarter2024 = date('d-m-Y', $lQ);
echo "<p> Last quarter : $dateLastQuarter2024</p>";echo "<br>";
// New moon 11 Jan 2024 11:57
$newMoon2024 = strtotime("2024-01-11 11:57");
$nM = ($newMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateNewMoon = date('d-m-Y', $nM);
echo "<p>New moon : $dateNewMoon </p>";echo "<br>";
// First quarter 18 Jan 2024 03:52
$firstQuarter2024 = strtotime("2024-01-18 03:52");
$fQ = ($firstQuarter2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFirstQuarter = date('d-m-Y', $fQ);
echo "<p>First quarter : $dateFirstQuarter </p>";echo "<br>";
// Full moon 25 Jan 2024 17:54
$fullMoon2024 = strtotime("2024-01-25 17:54");
$fM = ($fullMoon2024) + ($numberYear*$numberMonth*$lunarsecs);
$dateFullMoon = date('d-m-Y', $fM);
echo "<p>Full moon : $dateFullMoon</p>";echo "<br>";
?>
<?php
/*
Moon Phaser Demo
By: Minkukel
Date: 18-04-2020
*/
// Use current UTC date and time for this demo
date_default_timezone_set('Europe/Jersey');
$thedate = date('Y-m-d H:i:s');
$unixdate = strtotime($thedate);
// The duration in days of a lunar cycle
$lunardays = 29.53058770576;
// Seconds in lunar cycle
$lunarsecs = $lunardays * (24 * 60 *60);
// Date time of first new moon in year 2000
$new2000 = strtotime("2000-01-06 18:14");
// Calculate seconds between date and new moon 2000
$totalsecs = $unixdate - $new2000;
// Calculate modulus to drop completed cycles
// Note: for real numbers use fmod() instead of % operator
$currentsecs = fmod($totalsecs, $lunarsecs);
// If negative number (date before new moon 2000) add $lunarsecs
if ( $currentsecs < 0 ) {
$currentsecs += $lunarsecs;
}
// Calculate the fraction of the moon cycle
$currentfrac = $currentsecs / $lunarsecs;
// Calculate days in current cycle (moon age)
$currentdays = $currentfrac * $lunardays;
// Array with start and end of each phase
// In this array 'new', 'first quarter', 'full' and
// 'last quarter' each get a duration of 2 days.
$phases = array
(
array("new", 0, 1),
array("waxing crescent", 1, 6.38264692644),
array("first quarter", 6.38264692644, 8.38264692644),
array("waxing gibbous", 8.38264692644, 13.76529385288),
array("full", 13.76529385288, 15.76529385288),
array("waning gibbous", 15.76529385288, 21.14794077932),
array("last quarter", 21.14794077932, 23.14794077932),
array("waning crescent", 23.14794077932, 28.53058770576),
array("new", 28.53058770576, 29.53058770576),
);
// Find current phase in the array
for ( $i=0; $i<9; $i++ ){
if ( ($currentdays >= $phases[$i][1]) && ($currentdays <= $phases[$i][2]) ) {
$thephase = $phases[$i][0];
break;
}
}
// Spit it out
echo "<h2>Moon Phase Calculator</h2>";
echo "<p>Date and time: ".date("l, j F Y H:i:s", $unixdate)." In Gorey Jersey</p>";
echo "<h2>Constants used</h2>";
echo "<p>Duration of Lunar Cycle is: $lunardays days</p>";
//echo "<p>Date time of first new moon in 2000 is: 2000-01-06 18:14 UTC</p>";
echo "<h2>Calculated moon phase</h2>";
echo "<p>Percentage of lunation: ".round((100*$currentfrac),2)."%</p>";
echo "<p>The moon age is: ".round($currentdays,2)." days</p>";
echo "<p>The moon phase is: $thephase</p>";
?>
Re: Moon Phase Date webtags
Posted: Sun 18 Aug 2024 9:18 pm
by Mapantz
I thought I'd put that script in a file to see what the output was like.
Moon age is wrong
The illumination percentage is completely wrong
First and last quarter dates are wrong
It says it is a full moon, but technically its waxing gibbous
Re: Moon Phase Date webtags
Posted: Mon 19 Aug 2024 7:08 am
by AndyKF650
Hi there
I would suggest that you look up the word lunation, which is the period between successive new moons and has nothing to do with illumination levels.
Going back to the original script the author said that there was a 2 day variance for the actual description of the moon quarters. Today my site shows that the moon is full since it is 14.23 days out of a lunar cycle of 29.531 days between new moons.
Re: Moon Phase Date webtags
Posted: Mon 19 Aug 2024 9:24 am
by Mapantz
AndyKF650 wrote: ↑Mon 19 Aug 2024 7:08 am
Hi there
I would suggest that you look up the word lunation, which is the period between successive new moons and has nothing to do with illumination levels.
Ah OK.
But why is it expressed as a percentage?
Re 2 day variance for the quarters; that's pointless then. It's either right or wrong.
There's no point in showing wrong phase dates.
Re: Moon Phase Date webtags
Posted: Wed 21 Aug 2024 8:21 pm
by Mapantz
I did some searching and I found a PHP script called Solaris:
https://github.com/BitAndBlack/php-moon-phase
It seems to provide accurate dates for the phases for me, compared to those above.
You can call the dates for the current lunar cycle or the next lunar cycle.
I added the 4 phase dates to my site, but I made a little extra PHP stuff so that it checks the date of each phase against the current date.
If any of the current 4 phase dates have passed, it'll show the phase date of the next lunar cycle.
Re: Moon Phase Date webtags
Posted: Thu 22 Aug 2024 11:15 am
by mcrossley
Any calculation that uses the mean lunation period to calculate the lunation age from some full moon date/time in the past is going to give a value +/- 2 days or so. The lunation period varies with each cycle though the long-term mean is stable.
To determine the "age" in days of the current cycle MX uses a precalculated list of new moon dates (it is expensive in compute terms to calculate the new moon date accurately every time the web tag is called - it is an iterative process to narrow down on the required phase angle). To get the age, MX simply interpolates between the last and the next new moons. This is accurate to less than hour- enough for our purposes.
The phase angle is determined using astronomical calculations laid down by Jean Meeus which I have used before in other programs, they are accurate to about one minute. The moon descriptive phase (full, new etc) and percentage illumination are determined from the phase angle.
I'm unlikely to add the dates for next phases to MX, there are plenty of libraries out there in every language that already do this.