PHP | easter_date() Function

The easter_date() function is a built-in function in PHP which returns the Easter date in the year passed as an argument. The current year is taken as default year when no arguments are passed as parameter.

Syntax:

easter_date( $year )

Parameter: The function accepts one optional parameter $year which specifies the year whose Easter date is to be returned. The year can be a number between 1970 and 2037 only. It returns an error message when the year is out of range.

Return Value: It returns the Easter date on the given year which is passed in the argument. If no parameter is passed, it returns the Easter date of the current year.

Examples:



Input : 2018
Output : Apr-01-2018

Input : 2017
Output : Apr-16-2017

Below programs illustrates the easter_date() function:

Program 1: The program demonstrates the function when no parameter is passed.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// working of easter_date() function 
// when no parameter is passed 
  
// prints the date of Easter of year 2018
// when no parameter is passed 
echo date("M-d-Y", easter_date()), "\n";   
  
// current year to verify 
$year = 2018; 
echo date("M-d-Y", easter_date($year));   
?>

chevron_right


Output:

Apr-01-2018
Apr-01-2018

Program 2: The program demonstrates the function when parameter is passed.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// working of easter_date() function 
// when parameter is passed 
  
  
$year = 2017; 
echo date("M-d-Y", easter_date($year)), "\n"
  
$year = 2010; 
echo date("M-d-Y", easter_date($year)), "\n"
  
$year = 2000; 
echo date("M-d-Y", easter_date($year)); 
?>

chevron_right


Output:

Apr-16-2017
Apr-04-2010
Apr-23-2000

Program 3: The program demonstrates the function when parameter is passed out of range.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the
// working of easter_date() function 
// when parameter is out of range
  
$year = 2050; 
  
echo date("M-d-Y", easter_date($year)), "\n"
  
?>

chevron_right


Output:

PHP Warning:  easter_date(): This function is only valid 
for years between 1970 and 2037 inclusive in
/home/df540ecbab7094243e7668326260e785.php on line 8

Reference:
http://php.net/manual/en/function.easter-date.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.