easter_date

(PHP 4, PHP 5, PHP 7, PHP 8)

easter_dateObtener la fecha Unix para la medianoche de Pascua de un año dado

Descripción

easter_date(int $year = date("Y"), int $method = CAL_EASTER_DEFAULT): int

Devuelve la fecha Unix correspondiente a la medianoche de Pascua del año dado.

Advertencia

Esta función generará una advertencia si el año está fuera del rango de fechas Unix (es decir típicamente, antes de 1970 o después de 2037 en sistemas 32 bits).

La fecha del Domingo de Pascua fue definida por el Concilio de Nicea en el año 325 D.C. como el domingo después de la primera luna llena que cae en o después del Equinocio de Primavera. El equinocio se asume que cae en el 21 de marzo, por lo que el cálculo se reduce a determinar la fecha de la luna llena y la fecha del siguiente domingo. El algoritmo que se usa aquí fue introducido alrededor del año 532 por Dionisio el Exiguo. Bajo el Calendario Juliano (para años anteriores a 1753) se usa un simple ciclo de 19 años para rastrear las fases de la luna. Bajo el Calendario Gregoriano (para años posteriores a 1753 - concebido por Clavio y Lilio, e introducido por el papa Gregorio XIII en Octubre de 1582, e introducido en Gran Bretaña y sus colonias en Septiembre de 1752) se añadieron dos factores de corrección para hacer el ciclo más exacto.

Parámetros

year

El año como un número entre 1970 y 2037. Si se omite, el valor predeterminado será el del año actual según la hora local.

method

Permite que las fechas de Pascua se calculen en base al calendario Juliano cuando se establece para CAL_EASTER_ALWAYS_JULIAN. véase también constantes de calendario.

Valores devueltos

El Domingo de Pascua como fecha Unix.

Ejemplos

Ejemplo #1 Ejemplo de easter_date()

<?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

?>

Notas

Nota:

easter_date() depende de las función de hora en C de su sistema en vez de usar las funciones de fecha y hora internas de PHP. Como consecuencia, easter_date() utiliza la variable de entorno TZ para determinar la zona horaria en la que debería operar, en lugar de usar la zona horaria predeterminada de PHP, la cual podría resultar en un comportamiento inesperado al usar esta función junto con otras funciones de fecha de PHP.

Como atajo, se puede usar easter_days() con DateTime y DateInterval para calcular el inico de la Semana Santa en la zona horario de su PHP como sigue:

<?php
function get_easter_datetime($año) {
$base = new DateTime("$año-03-21");
$días = easter_days($año);

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

foreach (
range(2012, 2015) as $año) {
printf("La Semana Santa del %d cae en %s\n",
$año,
get_easter_datetime($año)->format('F j'));
}
?>

El resultado del ejemplo sería:

La Semana Santa del 2012 cae en April 8
La Semana Santa del 2013 cae en March 31
La Semana Santa del 2014 cae en April 20
La Semana Santa del 2015 cae en April 5

Ver también

  • easter_days() - Obtener el número de días despúes del 21 de marzo en el cuál cae Pascua para un año dado para calcular la Pascua antes de 1970 o después de 2037

add a note add a note

User Contributed Notes 6 notes

up
23
maxie
15 years ago
To compute the correct Easter date for Eastern Orthodox Churches I made a function based on the Meeus Julian algorithm:

<?php
function orthodox_eastern($year) {
   
$a = $year % 4;
   
$b = $year % 7;
   
$c = $year % 19;
   
$d = (19 * $c + 15) % 30;
   
$e = (2 * $a + 4 * $b - $d + 34) % 7;
   
$month = floor(($d + $e + 114) / 31);
   
$day = (($d + $e + 114) % 31) + 1;
   
   
$de = mktime(0, 0, 0, $month, $day + 13, $year);
   
    return
$de;
}
?>
up
6
Alexander Bliznyuk
6 years ago
Thank you, @Maxie, for algorythm for computing Orthodox Easter date.
It can be improved though. You added 13 days in order to map Julian calendar to Gregorian.  But 13 days is not a constant. It's an accumulated error fixed in Gregorian and should be calculated with this formula: (int)($year / 100) - (int)($year / 400) - 2
up
10
py dot lebecq at gmail dot com
14 years ago
I recently had to write a function that allows me to know if today is a holiday.

And in France, we have some holidays which depends on the easter date. Maybe this will be helpful to someone.

Just modify in the $holidays array the actual holidays dates of your country.

<?php
/**
* This function returns an array of timestamp corresponding to french holidays
*/
protected static function getHolidays($year = null)
{
  if (
$year === null)
  {
   
$year = intval(date('Y'));
  }
   
 
$easterDate  = easter_date($year);
 
$easterDay   = date('j', $easterDate);
 
$easterMonth = date('n', $easterDate);
 
$easterYear   = date('Y', $easterDate);

 
$holidays = array(
   
// These days have a fixed date
   
mktime(0, 0, 0, 11$year),  // 1er janvier
   
mktime(0, 0, 0, 51$year),  // Fête du travail
   
mktime(0, 0, 0, 58$year),  // Victoire des alliés
   
mktime(0, 0, 0, 714, $year),  // Fête nationale
   
mktime(0, 0, 0, 815, $year),  // Assomption
   
mktime(0, 0, 0, 11, 1$year),  // Toussaint
   
mktime(0, 0, 0, 11, 11, $year),  // Armistice
   
mktime(0, 0, 0, 12, 25, $year),  // Noel

    // These days have a date depending on easter
   
mktime(0, 0, 0, $easterMonth, $easterDay + 2$easterYear),
   
mktime(0, 0, 0, $easterMonth, $easterDay + 40, $easterYear),
   
mktime(0, 0, 0, $easterMonth, $easterDay + 50, $easterYear),
  );

 
sort($holidays);
 
  return
$holidays;
}
?>
up
2
Guillaume Dufrene
10 years ago
I found a problem with holidays timestamp computation and daylight saving time.
An article about it at http://goo.gl/76t31 (in french only, sorry).

In summary, this year (2013) easter begins before adding an hour for daylight saving time (occured sunday at 3:00). It means that if you do $easter + X, where x is a number of seconds equivalent to one day, 39 days or 50 days, the result is not equals to a midnight timestamp...

Here a function to check if a midnight timestamp is equals to an holiday :

function isHoliday( $ts ) {
// Licence : Creative Commons (BY)
// By Webpulser - http://goo.gl/76t31
  $fixed_holidays = array( ’01-01′, ’01-05′, ’08-05′, ’14-07′, ’15-08′, ’11-11′, ’25-12′ );
  $format = ‘d-m’;

$dm = date($format, $ts);
  if ( in_array($dm, $fixed_holidays) ) return true;

$easter = easter_date( date(‘Y’, $ts) );
  if ( date($format, $easter +   86400) == $dm ) return true;
  if ( date($format, $easter + 3369600) == $dm ) return true;
  if ( date($format, $easter + 4320000) == $dm ) return true;

return false;
}

feel free to use / modify.
up
0
adwil at live dot com
9 years ago
Hey, recently I needed a function to get realization dates in online shop, so here it is (ready to go for polish users, please adjust your dates for any other country):

<?php
function getWorkday($date1,$workDays) {
       
$workDays = (int)$workDays;
        if (
$workDays <= 0)
            return
null;

       
$date1=strtotime('-1 day',strtotime($date1));

       
$lastYear = null;
       
$hol=array('01-01','01-06','05-01','05-03','08-15','11-01','11-11','12-25','12-26');  //array of month-date of static holidays (these are from Poland)
       
$i = 0;
        while (
$i<=$workDays) {
           
$year = date('Y', $date1);
            if (
$year !== $lastYear){
               
$lastYear = $year;
               
$easter = date('m-d', easter_date($year));
               
$date = strtotime($year . '-' . $easter); // easter
               
$easterSec = date('m-d', strtotime('+1 day', $date)); // easter monday
               
$greens = date('m-d', strtotime('+49 days', $date)); // zielone swiatki
               
$cc = date('m-d', strtotime('+60 days', $date)); // boze cialo
               
$hol[] = $easter;
               
$hol[] = $easterSec;
               
$hol[] = $greens;
               
$hol[] = $cc;
            }
           
$weekDay=date('w',$date1);
            if (!(
$weekDay==0 || $weekDay==6 || in_array(date('m-d',$date1),$hol)))
               
$i++;

           
$date1=strtotime('+1 day',$date1);
        }
        return
date('Y-m-d',$date1);
    }
?>
up
0
phpuser
19 years ago
The algorithm from Bigtree is correct if you add some (int) cast
<?php
  
function easter_date ($Year) {
  
      
/*
       G is the Golden Number-1
       H is 23-Epact (modulo 30)
       I is the number of days from 21 March to the Paschal full moon
       J is the weekday for the Paschal full moon (0=Sunday,
         1=Monday, etc.)
       L is the number of days from 21 March to the Sunday on or before
         the Paschal full moon (a number between -6 and 28)
       */
      

        
$G = $Year % 19;
        
$C = (int)($Year / 100);
        
$H = (int)($C - (int)($C / 4) - (int)((8*$C+13) / 25) + 19*$G + 15) % 30;
        
$I = (int)$H - (int)($H / 28)*(1 - (int)($H / 28)*(int)(29 / ($H + 1))*((int)(21 - $G) / 11));
        
$J = ($Year + (int)($Year/4) + $I + 2 - $C + (int)($C/4)) % 7;
        
$L = $I - $J;
        
$m = 3 + (int)(($L + 40) / 44);
        
$d = $L + 28 - 31 * ((int)($m / 4));
        
$y = $Year;
        
$E = mktime(0,0,0, $m, $d, $y);

         return
$E;

   }
?>
To Top