Retreiving current Lunar Phase

Would anyone here happen to know how I might retrieve the current lunar phase using ColdFusion?  I was thinking of perhaps finding and setting up some kind of database for this, but I'm now thinking that this might not even be necessary.  

Anyone know how I might achieve this programatically?  I've already looked in to using the DateLib UDF, -- but it doesn't seem to handle lunar phases.  Surely, this type of functionality can't be that complicated.  Anyone care to lend a hand?

 - Yvan
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is a link:

Looks like there is a new moon approx. every 29.53058885 days but it is a complicated formula if you want to be exact due to the elliptical orbits.
IDEASDesignAuthor Commented:
Well, since I'd like to retrieve the other lunar phases as well (not just the full moon phase), .. it seems that I might require some kind of database for this.   Anyone else have any suggestions?

- Yvan
The following may help:

Perhaps you can find something there that you can request, parse, and query for the needed info.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

You can combine the ideas given:  Check the accurate data given at the unno sites against a quick calculation using the given lunar period.  

Starting at a date-time of a full moon, you get another full moon every period (29.53058885).  

You will get the new moon at period/2 + period + 2*period ...

You will get a first quarter moon at period/4 + period + 2*period ...

You will get a third quarter moon at 3*period/4 + period + 2*period ...

I haven't done this calculation and checked it against the usno data but I would be surprised if it is not very accurate.  Keep in mind that you will be calculating a date and time of day, but that all you really need is the date of the moon phase.  This gives you lots of room to accept some deviation due to details.
Keep in mind, however that the accuracy of these calculations will be based on the timezone used for the origin of time.  For all others, the accuracy will be any number of hours incorrect.
I don't know exactly how to do this, but this library looks like it has the support you are looking for.
It is opensource and runs in the JRE. If you are using cf MX, you should be able to install the class library and use it... not something I have expertise in doing, other than to know this is entirely possible.
IDEASDesignAuthor Commented:
I appreciate all the feedback you folks have been giving me. Although I do understand the calculations that have been provided, I suspect that this approach would be a bit too complicated, considering that I'd have to map the span of days to the actual calendar dates.  And in examining the behavior of the Windows executable for the mondtag library, I do not believe that the JAR file equivalient of this would be able to achieve the type of functionionality I am looking for.  

What would be most ideal is if there was some kind of web service available that would allow me to pass a specific calendar date to it, and have it return the name of the lunar phase to me (New Moon, First Quarter, Full Moon, or Last Quarter) .  Anyone here know if something like this exists?  

- Yvan

P.S. The point that was brought up regarding how the timezone effects the lunar phases is perfectly valid.  However, at the point in time, I do not need that level of accuaracy. Thank you for mentioning it, however.  
Here is a function that gives the phase of the moon.  Input is a datetime in UTC.  Output is full, last quarter, new, or first quarter.

I tested it against the usno data and found that it produces good results over at least a 10 year period.  (They only show 10 years of data)

<!--- index.cfm   Dan Kelly   060418 --->

<cfif isDefined("form.dateMoon")>
  <cfset dateMoon = form.dateMoon>
  <cfset dateMoon=now()>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "TR/html4/loose.dtd">
<title>Moon Phase per Date</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<form name="formMoon" id="formMoon" method="post" action="index.cfm" >

Date:<input type="text" name="dateMoon" value="<cfoutput>#dateMoon#</cfoutput>" >
<input type="submit" value="Submit">


<cffunction name="getPhase" returntype="string">
      <cfargument name="dateMoon" type="date" required="yes">
      <cfset dateFull = createDateTime(2000, 1, 21, 4, 40, 0)>
      <cfset periodSeconds = 29.530589*86400>
      <cfset futureSeconds = dateDiff("s", dateFull, arguments.dateMoon)>
      <cfset phase = (futureSeconds mod periodSeconds)/periodSeconds>
      <cfif (phase gte .875) or (phase lt .125)><cfset result="full: #phase#">
      <cfelseif (phase gte .125) and (phase lt .375)><cfset result="last quarter: #phase#">
      <cfelseif (phase gte .375) and (phase lt .625)><cfset result="new: #phase#">
      <cfelse><cfset result="first quarter: #phase#"></cfif>
      <cfreturn result>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IDEASDesignAuthor Commented:
Perfect!  Thank you so much!  This is exactly what I was looking for.  

You win :)

- Yvan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.