Here we are not going to try find the actual age of the Moon, which is several billion years old, but rather the age of the Moon since the last new Moon. This is just the amount of time in days, and fraction of days passed since the new Moon.

The Normalize() function just gets the fraction part of a number and if the resulting number is less than 1, returns 1 – number, otherwise it returns the resulting number itself.

The length of one lunar cycle is 29.53 days, so what the calculation does is works out how many lunar cycles have passed since a known new Moon. It then gets the fraction part, multiplied by the length of a lunar cycle, and we then have the age of the current lunar cycle in days.

		public static double CalcMoonAge(DateTime dDate, int iZone)
		{
			double fJD, fIP, fAge;

			fJD = UraniaTime.GetJulianDay(dDate, iZone);
			fIP = Normalize((fJD - 2451550.1) / 29.530588853);
			fAge = fIP*29.530588853;
            return fAge;
		}

		private static double Normalize(double fN)
		{
			fN = fN - Math.Floor(fN);
			if (fN < 0)
			{
				fN = fN + 1;
			}
			return fN;
		}
Share