know of a function of how to only show the days of the current month without counting Saturdays, Sundays and holidays of the country Colombia I found this object to detect the holidays.
class festivos
{
private $hoy;
private $festivos;
private $ano;
private $pascua_mes;
private $pascua_dia;
public function festivos($ano='')
{
$this->hoy=date('d/m/Y');
if($ano=='')
$ano=date('Y');
$this->ano=$ano;
$this->pascua_mes=date("m", easter_date($this->ano));
$this->pascua_dia=date("d", easter_date($this->ano));
$this->festivos[$ano][1][1] = true; // Primero de Enero
$this->festivos[$ano][5][1] = true; // Dia del Trabajo 1 de Mayo
$this->festivos[$ano][7][20] = true; // Independencia 20 de Julio
$this->festivos[$ano][8][7] = true; // Batalla de Boyacá 7 de Agosto
$this->festivos[$ano][12][8] = true; // Maria Inmaculada 8 diciembre (religiosa)
$this->festivos[$ano][12][25] = true; // Navidad 25 de diciembre
$this->calcula_emiliani(1, 6); // Reyes Magos Enero 6
$this->calcula_emiliani(3, 19); // San Jose Marzo 19
$this->calcula_emiliani(6, 29); // San Pedro y San Pablo Junio 29
$this->calcula_emiliani(8, 15); // Asunción Agosto 15
$this->calcula_emiliani(10, 12); // Descubrimiento de América Oct 12
$this->calcula_emiliani(11, 1); // Todos los santos Nov 1
$this->calcula_emiliani(11, 11); // Independencia de Cartagena Nov 11
//otras fechas calculadas a partir de la pascua.
$this->otrasFechasCalculadas(-3); //jueves santo
$this->otrasFechasCalculadas(-2); //viernes santo
$this->otrasFechasCalculadas(36,true); //Ascención el Señor pascua
$this->otrasFechasCalculadas(60,true); //Corpus Cristi
$this->otrasFechasCalculadas(68,true); //Sagrado Corazón
// otras fechas importantes que no son festivos
// $this->otrasFechasCalculadas(-46); // Miércoles de Ceniza
// $this->otrasFechasCalculadas(-46); // Miércoles de Ceniza
// $this->otrasFechasCalculadas(-48); // Lunes de Carnaval Barranquilla
// $this->otrasFechasCalculadas(-47); // Martes de Carnaval Barranquilla
}
protected function calcula_emiliani($mes_festivo,$dia_festivo)
{
// funcion que mueve una fecha diferente a lunes al siguiente lunes en el
// calendario y se aplica a fechas que estan bajo la ley emiliani
//global $y,$dia_festivo,$mes_festivo,$festivo;
// Extrae el dia de la semana
// 0 Domingo … 6 Sábado
$dd = date("w",mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano));
switch ($dd) {
case 0: // Domingo
$dia_festivo = $dia_festivo + 1;
break;
case 2: // Martes.
$dia_festivo = $dia_festivo + 6;
break;
case 3: // Miércoles
$dia_festivo = $dia_festivo + 5;
break;
case 4: // Jueves
$dia_festivo = $dia_festivo + 4;
break;
case 5: // Viernes
$dia_festivo = $dia_festivo + 3;
break;
case 6: // Sábado
$dia_festivo = $dia_festivo + 2;
break;
}
$mes = date("n", mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano))+0;
$dia = date("d", mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano))+0;
$this->festivos[$this->ano][$mes][$dia] = true;
}
protected function otrasFechasCalculadas($cantidadDias=0,$siguienteLunes=false)
{
$mes_festivo = date("n", mktime(0,0,0,$this->pascua_mes,$this->pascua_dia+$cantidadDias,$this->ano));
$dia_festivo = date("d", mktime(0,0,0,$this->pascua_mes,$this->pascua_dia+$cantidadDias,$this->ano));
if ($siguienteLunes)
{
$this->calcula_emiliani($mes_festivo, $dia_festivo);
}
else
{
$this->festivos[$this->ano][$mes_festivo+0][$dia_festivo+0] = true;
}
}
public function esFestivo($dia,$mes)
{
//echo (int)$mes;
if($dia=='' or $mes=='')
{
return false;
}
if (isset($this->festivos[$this->ano][(int)$mes][(int)$dia]))
{
return true;
}
else
{
return FALSE;
}
}
}
Cheers! You can use PHP 's DateTime class with the DateInterval class so you can create a DatePeriod and iterate over it with a foreach.
Here we initialize all variables
To take all the dates of the current month you can use the DateTime constructor to initialize the first and last day of the month
We create the DatePeriod with the established parameters
Then in an array we assign the holidays
And then we iterate
Tested with php 7.0 it prints this:
03-01-2017 03-02-2017 03-03-2017 03-06-2017 03-07-2017 03-08-2017 03-09-2017 03-10-2017 03-13-2017 03-14-2017 03-15-2017 03-16-2017 03-17-2017 03-21-2017 03-22-2017 03-23-2017 03-24-2017 03-27-2017 03-28-2017 03-29-2017 30-03-2017
A simple way to do what you're looking for would be to store the holidays in an array.
When you do that you just have to get the days of the current month:
Now it's time to iterate the days:
Inside the loop you only have to check if it's Saturday, Sunday or if the day is in the array, if this happens you don't show it, you store it etc. In the if it is important that you take into account the way you store the date in the array, for example store it in this format:
To generate the date in the loop you just have to concatenate:
Getting:
I have put the year but it would be best not to put it so that it works for all years.
I hope I understood what you are looking for.
All the best!
I am trying to make a function in php that allows me to add the days given a date but does not count the weekends. Now I have managed to add the days and show them to me as I want, that is, add the days but every 5 years I add 3 days, so far everything works well, it tells me how many days it corresponds to and how old it is. but now they changed everything and they ask me not to be continuous days but business days and to start the first year with 15 days and for each year from the date of admission I add one more day until I am 15 years old and if I stop I am trying to solve but I don't know if you can guide me.
I don't know if I understand myself correctly.
I place the code as I have it and as it is currently working for me.