PHP- Validaciones – Date between
Función que nos indica si una fecha en formato yyyy-mm-dd está comprendida entre otras dos.
Se puede indicar si es un entorno cerrado, con lo cual se comprueba si el inicio y el final es también igual a la fecha preguntada.
/**
* Class HelperValidate
*/
abstract class HelperValidate
{
/**
* Devuelve true si una fecha esta entre otras dos
*
* @param string $fecha
* @param string $inicio
* @param string $fin
* @param bool $cerrado
*
* @return bool
*/
public static function isBetweenDates( $fecha,
$inicio,
$fin,
$cerrado = true)
{
if ($cerrado) {
if ($inicio === $fecha || $fin === $fecha) {
return true;
}
}
return ( HelperDate::getDif($inicio, $fecha) < 0 &&
HelperDate::getDif($fin, $fecha) > 0);
}
}
Funciones relacionadas
- HelperDate::getDif : Como saber qué fecha en formato yyyy-mm-dd es mayor
