Asymptomatic

Simple Easter Calculation in PHP

After reading a couple of articles on how to compute the date of Easter, I wrote up this simple PHP code snippet that will do it for any date from 2000 to 2199.

?php $year = 2006; $G = $year % 19 + 1; $S = (11 * $G - 6) % 30; $S = $S == 0 ? 1 + ($G > 12 ? 1 : 0): $S; $FullMoon = mktime(0, 0, 0, 4, 19 - $S, $year); $d_ary = getdate($FullMoon); $d_ary['mday'] += $d_ary['wday'] > 0 ? 7 - $d_ary['wday'] : 0; $Easter = mktime(0, 0, 0, $d_ary['mon'], $d_ary['mday'], $d_ary['year']); echo date('D, F jS', $Easter); ?>
Continues here →

Also of interest to me is calculating full moon dates, which is what this code needs to do to forecast Easter. I wonder if there's code out there to do that more reliably.

Other Posts

Comments

  1. so you know as far as I know this is the best calculation (not the simpler one I used for my half arsed version)

    Moon Phase in both QBASIC and JavaScript

    When I get home I'm going to work out a php version. Should be interesting to compare notes.

  2. calculating the phase of the moon is a pain in the arse. There's a mathmatical forumula for it, but I can't find two places that agree what it is.

    I used a simple one to create a nice blog graphic that showed the current phase of the moon (and could show any dates phase) but it wasn't perfectly accurate. Sometimes it was a night or two out. Still... not too bad for a first try.

    If you find a good calulation please let me know!

  3. The algorithm works only to 2037 for me. Also 2001, 2021, and 2025 are not the same as other published tables...

swindler-cave
Real Time Web Analytics