2 of 11 added 5 characters in body

Calculate the Lunar Phase



In this challenge you have to calculate the moon's phase for a given date.

This challenge is inspired by the game psycho social audiovisual experiment "Superbrothers: Sword & Sworcery EP". In S:S&S EP the moon's phases are important to the outcome of the adventure as some events occur only at a specific point in time.

Screenshot from Superbrothers: Sword & Sworcery EP

Mild game spoilers ahead:

Besides the intended way of putting your device aside until a certain phase is reached, you can also manipulate the phase in a secret place called "The Moon Grotto". Or you can cheat and change the date setting of your device. Keep in mind that cheating is penalized though.

Now, we want to know which lunar phase is present on a specific date. Each main phase from new moon to full moon and way back is about 7.38 days long. The whole lunar cycle is roughly 29.52 days. Based on these values various methods of calculation exist.1


  • A date, starting at 1 January 1970.
  • You can choose one of the following formats: yyyy-mm-dd, dd.mm.yyyy, dd/mm/yyyy, yyyymmdd or ddmmyyyy.


Output the index of lunar phase based on this zero-indexed array:

['New moon', 'Waxing crescent', 'First quarter', 'Waxing gibbous', 'Full moon', 'Waning gibbous', 'Third quarter', 'Waning crescent`]


  • You can write a program or a function. If you go with an anonymous function, please include an example of how to invoke it.
  • Input is accepted from STDIN, command line arguments or as function parameters.
  • This is so shortest answer in bytes wins.
  • Built-ins or external libraries are not allowed.2
  • Standard loopholes are disallowed.


14.12.2016 | 4 | Full moon
28.01.2016 | 5 | Waning gibbous
19.01.2016 | 3 | Waxing gibbous
17.01.2016 | 2 | First quarter
12.01.2016 | 1 | Waxing crescent
24.01.2016 | 4 | Full moon
11.08.1999 | 0 | New moon
16.10.1983 | 3 | Waxing gibbous
04.07.1976 | 2 | First quarter
29.11.1970 | 0 | New moon


Reduce your byte count and withdraw:

  • 15% – Print the actual name of the phase as listed in section Output.
  • 25% – Print the dates of the upcoming new and full moon separated by a whitespace or newline on empty input.

1 For example: Calculating phase on Wikipedia.
2 Sorry Mathematica.