Important alert: (current site time 7/15/2013 9:11:42 PM EDT)
 

VB icon

Calculating Easter

Email
Submitted on: 4/29/2003 10:54:24 AM
By: Randy McCleary 
Level: Beginner
User Rating: By 3 Users
Compatibility: 5.0 (all versions)
Views: 15145
(About the author)
 
     Ever wondered how to Calculate the date of easter? Well here's a simple Perl script that will just do that. It shows how to get the date of Easter for the current year and for the next 25 Years in the Future.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
=**************************************
= for :Calculating Easter
=**************************************
The algorithm is based on the algorithm of Oudin (1940) and quoted in "Explanatory Supplement to the Astronomical Almanac", P. Kenneth Seidelmann, editor.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Calculating Easter
= Description:Ever wondered how to Calculate the date of easter? Well here's a simple Perl script that will just do that. It shows how to get the date of Easter for the current year and for the next 25 Years in the Future.
= By: Randy McCleary
=
= Inputs:Year
=
= Returns:Date Of Easter
=
= Assumes:The algorithm is based on the algorithm of Oudin (1940) and quoted in "Explanatory Supplement to the Astronomical Almanac", P. Kenneth Seidelmann, editor.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=460&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
########################################################################
# A Simple script that Calculates the date of Easter and shows how
# to calculate future dates of easter.
########################################################################
use POSIX;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;
my ($Year2, $Century, $G, $K, $I, $J, $L, $EasterMonth, $EasterDay, $p);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $month_name= 'jan';
$year += 1900;
if (param()) {
	$year = param('y');
}
print header;
print "<b>\n";
######################################
# Print Date of easter This year
######################################
&CalculateEaster();
print "</b><br><br>\n";
######################################
# Print the next 25 Years of Easter
######################################
print "Next 25 Years<br>\n";
for ($p = 1; $p <= 25; $p += 1) {
	&CalculateEaster();
}
######################################
# Subroutine to Calculate the date of
# Easter for a given year
######################################
sub CalculateEaster {
	$Year2 = $year + $p;
	$Century = int $Year2 / 100;
	$G = $Year2 % 19;
	$K = int (($Century - 17) / 25);
	$I = ($Century - int ($Century / 4) - int (($Century - $K) / 3) + 19 * $G + 15) % 30;
	$I = $I - (int ($I / 28)) * (1 - (int ($I / 28)) * (int (29 / ($I + 1))) * (int ((21 - $G) / 11)));
	$J = ($Year2 + int ($Year2 / 4) + $I + 2 - $Century + int ($Century / 4)) % 7;
	$L = $I - $J;
	
	$EasterMonth = 3 + int (($L + 40) / 44);
	$EasterDay = $L + 28 - 31 * (int ($EasterMonth / 4));
	
	$month_name = ("January", "February", "March", 
							"April", "May", "June", "July", 
							"August", "September", "October", 
							"November", "December")[$EasterMonth-1];
					
	print "Easter is $month_name $EasterDay, $Year2 <br>\n";
}


Other 28 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

5/6/2003 10:17:04 AMstephen antony

good work men cool i think you did it well as i know the method
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.