hello,
i need the calculation for the moon phases - depending on a given date.
does anybody know such a function ? or something else ? - would be great
TIA
Gernot
hello,
i need the calculation for the moon phases - depending on a given date.
does anybody know such a function ? or something else ? - would be great
TIA
Gernot
i solved the problem by myself....
function GetMoonPhase($timestamp) {
$days = abs(gregorianToJD(1, 12, 1975) - gregorianToJD(date("m",$timestamp),date("d",$timestamp), date("Y",$timestamp)));
$part = $days%$moonphase;
if ($part==0) $part = 29;
return $part;
}
$timestamp is a unix-timestamp of the day you want to calculate the moon - phase.
1 .... newmoon
2-14.. increase
15.... full moon
16-29. decrease
maybe i could help some people...
i've forgotten the variable $moonphase
$moonphase = 29.5306;
:-))
Thanks ! I was searching for a moonphase PHP script and this one is great
I will put it in my website, should I add a copyright ?
//Returns an array with all the phases of the moon for a whole year function
CalculateMoonPhases( $Y ) {
//Converted from Basic by Roger W. Sinnot, Sky & Telescope, March 1985.
//Converted from javascript by Are Pedersen 2002
//Javascript found at http://www.stellafane.com/moon_phase/moon_phase.htm
$R1 = 3.14159265 / 180;
$U = false;
$s = ""; // Formatted Output String
$K0 = intval(($Y-1900)12.3685);
$T = ($Y-1899.5) / 100;
$T2 = $T$T; $T3 = $T$T$T;
$J0 = 2415020 + 29$K0;
$F0 = 0.0001178$T2 - 0.000000155$T3;
$F0 += (0.75933 + 0.53058868$K0);
$F0 -= (0.000837$T + 0.000335$T2);
//X In the Line Below, F is not yet initialized, and J is not used before it set in the FOR loop.
//X J += intval(F); F -= INT(F);
//X Ken Slater, 2002-Feb-19 on advice of Pete Moore of Houston, TX
$M0 = $K00.08084821133;
$M0 = 360($M0 - intval($M0)) + 359.2242;
$M0 -= 0.0000333T2;
$M0 -= 0.00000347T3;
$M1 = $K00.07171366128;
$M1 = 360($M1 - intval($M1)) + 306.0253;
$M1 += 0.0107306$T2;
$M1 += 0.00001236$T3;
$B1 = $K00.08519585128;
$B1 = 360($B1 - intval($B1)) + 21.2964;
$B1 -= 0.0016528$T2;
$B1 -= 0.00000239$T3;
for ( $K9=0; $K9 <= 28; $K9=$K9+0.5 ) {
$J = $J0 + 14$K9; $F = $F0 + 0.765294$K9;
$K = $K9/2;
$M5 = ($M0 + $K29.10535608)$R1;
$M6 = ($M1 + $K385.81691806)$R1;
$B6 = ($B1 + $K390.67050646)$R1;
$F -= 0.4068sin($M6);
$F += (0.1734 - 0.000393$T)sin($M5);
$F += 0.0161sin(2$M6);
$F += 0.0104sin(2$B6);
$F -= 0.0074sin($M5 - $M6);
$F -= 0.0051sin($M5 + $M6);
$F += 0.0021sin(2$M5);
$F += 0.0010sin(2*$B6-$M6);
$F += 0.5 / 1440; //Adds 1/2 minute for proper rounding to minutes per Sky & Tel article
$J += intval($F); $F -= intval($F);
//Convert from JD to Calendar Date
$julian=$J+round($F);
$s = jdtogregorian ($julian);
//half K
if (($K9-floor($K9))>0){
if (!$U){
//New half
$phases[$s]="ny2";
}else{
//Full half
$phases[$s]="ne2";
}
}else{
//full K
if ( !$U ){
$phases[$s]="ny";
}else{
$phases[$s]="ne";
}
$U = !$U;
}
} // Next
return $phases;
} //End MoonPhase