Moon Phase Calculator

Those of you who would like to research moon phases might like to use these routines for calculating the phase of the moon, and days since the last new moon.  The routines round to the date whose Central time zone midday is nearest the moon date.  Enjoy!

function DayofMoon(s: string): integer;
var t: TDateTime;
begin {new moon 1-6-2000 at 12:14 Central}
  t:=StrToDate(s)-EncodeDate(2000,1,6)-EncodeTime(0,14,0,0);
  Result:=round(frac(t/29.530589)*29.530589); 
end;

function QtrOfMoon(s: string): integer;
var t: TDateTime;
begin
  t:=StrToDate(s)-EncodeDate(2000,1,6)-EncodeTime(0,14,0,0);
  Result:=trunc(frac(t/29.530589)*4)+1; 
end;

var s: string;
begin
  s:=InputBox('Moon Phases','Enter a date mm-dd-yyyy',DateToStr(Now));
  s:=Copy(s,1,2)+'/'+Copy(s,4,2)+'/'+Copy(s,7,4); 
  writeln(s,' ','Days since New=',DayOfMoon(s),' ','Quarter=',QtrOfMoon(s)); 
end;