I have a date that I want to condition. 12-27-2016. I want to check if within the period of dates from 20-12-2015 to 12-20-2016 it is fulfilled or not, as well as from 20-12-2016 to 20-12-2017. In the case of the first period 2015-2016, the date is not fulfilled. But if you must meet the 2016-2017 period and however you indicate that it is out of period.
Here is the screen and the code.
I also attach the code in PHP
<?php
$hoy = date('d-m-Y');
$fi = date("20-12-2001");
$fecha_ingreso = date("d-m-Y", strtotime($fi));
$anio_actual = date("Y");
$fecha_aniversario = date("d-m-" . $anio_actual . "", strtotime($fi));
echo "Fecha de Ingreso: " . $fecha_ingreso . "</br>";
echo "Fecha de Aniversario en el año 2016: " . $fecha_aniversario . "</br>";
echo "Comparar si el dia de hoy " . $hoy . " el empleado cumple Aniversario: </br>";
if ($fecha_aniversario == $hoy) {
echo "Hoy " . $hoy . " es su aniversario </br>";
} else {
echo "Hoy " . $hoy . " no es su aniversario </br>";
}
$periodo2015 = strtotime('-1 year', strtotime($fecha_aniversario));
$periodo2015 = date('d-m-Y', $periodo2015);
$periodo2017 = strtotime('+1 year', strtotime($fecha_aniversario));
$periodo2017 = date('d-m-Y', $periodo2017);
echo " Comparar si " . $hoy . " cumple el rango de :" . $periodo2015 . " al periodo " . $fecha_aniversario . " </br> ";
$fecha1 = new DateTime($hoy);
$fecha1 = $fecha1->format("d-m-Y");
$f2015 = new DateTime($periodo2015);
$f2015 = $f2015->format("d-m-Y"); //=> 2015
$f2016 = new DateTime($fecha_aniversario);
$f2016 = $f2016->format("d-m-Y"); //=> 2016
$f2017 = new DateTime($periodo2017);
$f2017 = $f2017->format("d-m-Y"); //=2017
function comprobarPeriodo20152016($fecha1, $f2015, $f2016)
{
return $fecha1 >= $f2015 && $fecha1 <= $f2016;
}
if (comprobarPeriodo20152016($fecha1, $f2015, $f2016)) {
echo " " . $fecha1 . " Esta dentro del periodo " . $f2015 . "-" . $f2016 . "</br>";
} else {
echo " " . $fecha1 . " Esta fuera del periodo " . $f2015 . "-" . $f2016 . "</br>"; // <= Resultado
}
echo "</br>";
echo " Comparar si " . $hoy . " cumple el rango de :" . $fecha_aniversario . " al periodo " . $periodo2017 . " </br> ";
function comprobarPeriodo20162017($fecha1, $f2016, $f2017)
{
return $fecha1 >= $f2016 && $fecha1 <= $f2017;
}
if (comprobarPeriodo20162017($fecha1, $f2016, $f2017)) {
echo " " . $fecha1 . " Esta dentro del periodo " . $f2016 . "-" . $f2017 . "</br>";
} else {
echo " " . $fecha1 . " Esta fuera del periodo " . $f2016 . "-" . $f2017 . "</br>"; // <= Resultado
}
echo "</br>";
?>
The first condition is fulfilled. It is not within the period 2015-2016 The second should be fulfilled. It is within the 2016-2017 period and it does not Thanks for your comments you are welcome