I will propose two possible solutions with PHP.
When you always use the same date format
If your dates are always in the day-month-year format you can use the explode
function from PHP to get the year and perform the condition:
$fecha = "20-12-2001";
$fechaDividida = explode("-", $fecha);
$anno = $fechaDividida[2];
if ($anno >= 2016 && $anno <=2017){
echo "Está dentro del periodo";
}else{
echo "Está fuera del periodo";
}
It will return Está fuera del periodo
for this specific case.
When you use different date formats
In this case you can use the strtotime
function along with the date
feature to get the year and then compare it to see if is within the range:
$fecha = "20-12-2001";
$anno = date('Y', strtotime($fecha));
if ($anno >= 2016 && $anno <=2017){
echo "Está dentro del periodo";
}else{
echo "Está fuera del periodo";
}
It will return Está fuera del periodo
for this specific case.
In the latter case you could use $fecha = "2001-12-20";
and it would give you the same result. Even $fecha = "2001/12/20";
or $fecha = "20/12/2001";
and the result would be the same.