Moon Phases for PHP Script (CSV format)
Generate a list of Moon Phase dates and times for any year with this free online tool. The format is CSV, so you can use it in PHP script, Javascript, or any other programming language or database. The data comes directly from the U.S. Navy Astronomical Applications API for Phases of the Moon.
Moon Phase Generator
PHP Script
The PHP script to get the moon phases downloads the date/times from the U.S. Navy Astronomical Applications API in JSON format. It converts the date/times from UTC to the selected time zone. Then, it prints the data in multiple formats as separate columns of a CSV file. You can download the CSV file and open it in Excel.
The columns available are:
- date - in month/day/year format
- time - in hour:minute AM/PM format
- phase - the moon phase spelled out
- phaseid - an ID from 1 to 4 for the moon phase
- datetime - the date/time im MySQL format - YYYY-MM-DD HH:MM:SS
- timestamp - the unix time stamp
- friendlydate - date in format like "January 1, 2011"
- timezone - in PHP timezone identifier format, like "America/New_York"
Developers
Please do not link directly to this data. It is not designed to be high performance and will slow down your application. Download the data and store it in your system.
Change Log
September 2024
Entering a range of years is fixed, and the file name includes the range if specified. The min/max year range is greatly increased to reflect the new capabilities of the API.
December 2022
I updated the page to use the new Moon Phases API provided by the U.S. Navy.
October 2019
This tool stopped working in 2019 when the old US Navy Moon Phases tool was removed. When I inquired about the outage, I received the following helpful and detailed response :
As of 24 October 2019 we had to shut down all of our web pages that contained active content (i.e. the online calculators) by order of one of our superior Commands due to new DoD cybersecurity rules. We are in the process of migrating our content to a more secure platform, and we anticipate that the sites will be restored on or about 31 October 2020.
A possible workaround for you might be MICA, USNO's standalone Windows Multi-year Interactive Computer Almanac. This software will replicate most of the various functions that we offered on our web pages.
MICA uses the same source code as the online calculators and the annual Astronomical Almanac. It is distributed by Willmann-Bell, Inc. More info can be found at https://www.willbell.com/almanacs/almanac_mica.htm.
An online calculation service is provided by our Almanac partner in the UK, Her Majesty's Nautical Almanac Office. The service is intended for personal non-commercial use. The URL is http://astro.ukho.gov.uk/.
Select the "Websurf 2.0" option and follow the prompts. While the location pages default to British cities, you can input your location/time zone or select a location from a map. The site supports a number of calculations that are similar to the ones that we had on our old site.
Geoffrey R Chester (CIV USN NAVOBSY DC), Public Affairs Officer, U.S. Naval Observatory, 9/8/2020
Disclaimer: This content is provided as-is. The information may be incorrect.