Articles on websites & etc.

§ Home > Index > Freeware

Moon Phases for PHP Script (CSV format)

Generate a list of Moon Phase dates and times for any year with this free online tool. This tool works again as of Dec. 2022! 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.

Moon Phase Generator

Enter a Year
Year must be between 1920 and 2035.
Enter a single year like 2010, or a range like 2010-2015.
Enter a time zone

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:


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.


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

In Dec. 2022, I updated the page to use the new Moon Phases API provided by the U.S. Navy.

Optimize your Google Ads Shopping Campaigns by using this Free Online Maximum CPC Bid Calculator for Google Shopping. Learn how to bid by product price range to increase the ROI on your Ad spend.
Created 2011-12-04, Last Modified 2022-12-18, © Shailesh N. Humbad
Disclaimer: This content is provided as-is. The information may be incorrect.