Funcion php que compara dos fechas con formato (dia/mes/año) y devuelve la diferencia con el mismo formato.
El código PHP
function compara_fechas($fecha1,$fecha2)
{
if (preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$fecha1))
list($dia1,$mes1,$año1)=split("/",$fecha1);
if (preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$fecha1))
list($dia1,$mes1,$año1)=split("-",$fecha1);
if (preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$fecha2))
list($dia2,$mes2,$año2)=split("/",$fecha2);
if (preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$fecha2))
list($dia2,$mes2,$año2)=split("-",$fecha2);
$dif = mktime(0,0,0,$mes1,$dia1,$año1) - mktime(0,0,0, $mes2,$dia2,$año2);
return ($dif);
}
