PHP Function Reference

PHP easter_date() Function



The PHP easter_date() function returns the Unix timestamp corresponding to midnight on Easter of the given year.

Note: This function will generate a warning if the year is outside of the range for Unix timestamps (i.e. typically before 1970 or after 2037 on 32bit systems).

Syntax

easter_date(year, mode)

Parameters

year Optional. Specify the year as a number between 1970 an 2037. If omitted or null, defaults to the current year according to the local time.
mode Optional. Allows Easter dates to be calculated based on the Julian calendar when set to CAL_EASTER_ALWAYS_JULIAN. Default is CAL_EASTER_DEFAULT.

Return Value

Returns the easter date as a unix timestamp.

Exceptions

NA.

Example:

The example below shows the usage of easter_date() function.

<?php
//Easter date for current year
echo date("M-d-Y", easter_date())."\n";
 
//Easter date for year 2015
echo date("M-d-Y", easter_date(2015))."\n";

//Easter date for year 2010
echo date("M-d-Y", easter_date(2010))."\n";

echo "\n";

//Easter date for year 2015 
//based on Julian calendar
echo date("M-d-Y", easter_date(2015, 
          CAL_EASTER_ALWAYS_JULIAN))."\n";

//Easter date for year 2010 
//based on Julian calendar
echo date("M-d-Y", easter_date(2010, 
          CAL_EASTER_ALWAYS_JULIAN))."\n";
?>

The output of the above code will be:

Apr-04-2021
Apr-05-2015
Apr-04-2010

Mar-30-2015
Mar-22-2010

Example:

Consider one more example which demonstrates the situation when passed parameter is out of range.

<?php
//Easter date for year 2050
echo date("M-d-Y", easter_date(2050))."\n";
?>

The output of the above code will be:

PHP Fatal error:  Uncaught ValueError: easter_date(): Argument #1 ($year) must be between 1970 and 2037 (inclusive) in Main.php:3
Stack trace:
#0 Main.php(3): easter_date()
#1 {main}
  thrown in Main.php on line 3

❮ PHP Calendar Reference