Open In App
Related Articles

PHP | easter_days() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

The easter_days() Function is a built-in function in PHP which returns the number of days after March 21, that the Easter Day is in the given year. When no year is given, the current year is taken as the default value.

Syntax:

easter_days( $year, $method )

Parameters: The function accepts two optional parameters as shown above and explained below:

  1. $year This parameter specifies the year. When no parameter is passed the current year is taken as the default value.
  2. $method – This parameter allows you to calculate easter dates based on other calendars. If the $method is set to CAL_EASTER_ROMAN, it uses the Gregorian calendar during the years 1582 – 1752.

Return Value: The function returns the number of days after March 21, that the Easter Day is in the given year. When no $year is passed as an argument the current year is taken as the default year and the number of days after March 21 of the current year is returned.

Examples:

Input :  $year = 2018
Output : 11

Input : $year = 2017
Output : 26  

Input: $year = 2015 $method = CAL_EASTER_ROMAN
Output : 15  

Below programs illustrates the use of easter_days() function:

Program 1: The program below explains the working of easter_days() function when no parameter is passed.




<?php
// PHP program to demonstrate the 
// easter_days() function 
// when no parameter is passed 
  
echo easter_days(), "\n";  
  
// verified by passing current year
$year = 2018; 
echo easter_days($year);  
?>


Output:

11
11

Program 2: The program below explains the working of easter_days() function when $year parameter is passed




<?php
// PHP program to demonstrate the 
// easter_days() function 
// when $year parameter is passed 
  
  
$year = 2015; 
  
// no of days for Easter after march 21 of year 2015
echo easter_days($year), "\n";  
  
  
// the Easter date of year 2015
echo date("M-d-Y", easter_date($year));     
?>


Output:

15
Apr-05-2015

Program 3: The program below explains the working of easter_days() function when both the parameters is passed.




<?php
// PHP program to demonstrate the 
// easter_days() function 
// when both parameters are passed 
  
  
$year = 2014; 
  
// no of days for Easter after march 21 of year 2014 
// of Gregorian Calendar
echo easter_days($year, CAL_EASTER_ROMAN), "\n";  
?>


Output:

30

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 Apr, 2018
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials