James John – Software Engineer

Check Every Year’s Easter Date Using PHP

Check Every Year’s Easter Date Using PHP

Hello there, was just surfing on PHP functions in their site and came accross this function and it works great! Though I don’t even know how the Easter is been calculated :)

Below is the script, copy it to a PHP file and save or download the attachment:

<?php function check_easter($year) {
    
$y getdate(easter_date($year));
    if(
$year<date('Y')) {
        
$word 'was';
    }
    else {
        
$word 'is';
    }
    echo 
'Easter Date for the Year '.$year.' '.$word.' on:<br/>
    <b>'
.$y['weekday'].' '.$y['mday'].' '.$y['month'].', '.$y['year'].'</b>';
}
?> <form action="" method="post">

<select name="year"><?php
$year 
1970;
if(isset(
$_POST['year'])) {
    echo 
'<option selected="selected">'.$_POST['year'].'</option>';
}
while(
$year<=2037) {
    echo 
'<option>'.$year.'</option>';
    
$year++;
}
?> </select> <input type="submit" value="Check Easter Date" />
</form>
<?php
    
if(isset($_POST['year'])) {
        
check_easter($_POST['year']);
    }
    
?>

Sorry, i don’t have a demo server but am sure its working :)

James John

Software Engineer