easter_date

Get Unix timestamp for midnight on Easter of a given year

&reftitle.description; `int` `easter_date` ``int``null```year`&null; `int` `mode` `CAL_EASTER_DEFAULT`

Returns the Unix timestamp corresponding to midnight on Easter of the given year.

The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar (for years before 1753) a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (for years after 1753 - devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.

&reftitle.parameters;

`year`

- The year must be a number between 1970 and 2037 for 32-bit systems, or between 1970 and 2,000,000,000 for 64-bit systems. If omitted or &null;, defaults to the current year according to the local time.

`mode`

- Allows Easter dates to be calculated based on the Julian calendar when set to `CAL_EASTER_ALWAYS_JULIAN`. See also calendar constants.

&reftitle.returnvalues;

The easter date as a unix timestamp.

&reftitle.errors;

A `ValueError` is thrown if the year is earlier than 1970 or later than 2037 when running on a 32-bit system, or later than 2,000,000,000 on a 64-bit system.

&reftitle.changelog;

&Version; | &Description;
8.3.0 | On 64-bit systems, the `year` parameter now accepts values within the range of 1970 to 2,000,000,000.
8.0.0 | `year` is nullable now.
8.0.0 | A `ValueError` is now thrown when `year` is outside the allowed range. Previously, an `E_WARNING` was raised and the function returned &false;.

&reftitle.examples;

### `easter_date` example

    <?php

    echo date("M-d-Y", easter_date(1999));        // Apr-04-1999
    echo date("M-d-Y", easter_date(2000));        // Apr-23-2000
    echo date("M-d-Y", easter_date(2001));        // Apr-15-2001

    ?>

### Using `easter_date` with `DateTime`

    <?php

    $timestamp = easter_date(2023);

    $datetime = new \DateTime();
    $datetime->setTimestamp($timestamp);

    echo $datetime->format('M-d-Y'); // Apr-09-2023

    ?>

&reftitle.notes;

`easter_date` relies on your system's C library time functions, rather than using PHP's internal date and time functions. As a consequence, `easter_date` uses the `TZ` environment variable to determine the time zone it should operate in, rather than using PHP's default time zone, which may result in unexpected behaviour when using this function in conjunction with other date functions in PHP.

As a workaround, you can use the `easter_days` with `DateTime` and `DateInterval` to calculate the start of Easter in your PHP time zone as follows:

    <?php
    function get_easter_datetime($year) {
        $base = new DateTime("$year-03-21");
        $days = easter_days($year);

        return $base->add(new DateInterval("P{$days}D"));
    }

    foreach (range(2012, 2015) as $year) {
        printf("Easter in %d is on %s\n",
               $year,
               get_easter_datetime($year)->format('F j'));
    }
    ?>

&example.outputs;

    Easter in 2012 is on April 8
    Easter in 2013 is on March 31
    Easter in 2014 is on April 20
    Easter in 2015 is on April 5

&reftitle.seealso;

- `easter_days` for calculating Easter before 1970 or after 2037