Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/08/2006, 14:37
GikaJavi
 
Fecha de Ingreso: agosto-2006
Mensajes: 121
Antigüedad: 17 años, 9 meses
Puntos: 0
No te compliques la vida. Aquí tienes las funciones que yo uso para estos menesteres:

Código PHP:
<?php

function compara_fechas($fecha1,$fecha2) {
// Devuelve > 0 si fecha1 > fecha2; menor < 0 alrevés o cero si so iguales . Funciona tanto en formato dd-mm-aa como dd/mm/aaaa
      
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);                         
}      

function 
suma_fechas($fecha,$ndias)
// Ejemplo: Si $fecha=10/11/2005 y $ndias=21 entonces devuelve 01/12/2005
{
  if (
preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$fecha))
          list(
$dia,$mes,$año)=split("/"$fecha);

  if (
preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$fecha))
          list(
$dia,$mes,$año)=split("-",$fecha);
    
$nueva mktime(0,0,0$mes,$dia,$año) + $ndias 24 60 60;
    
$nuevafecha=date("d-m-Y",$nueva);
  return (
$nuevafecha);

}


function 
resta_fechas($fecha1,$fecha2)
// Ejemplo: Si $fecha1=10/11/2006 y $fecha2=10/11/2005 entonces devuelve 365
{
  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);

  
$ndias=floor($dif/(24*60*60));
  return(
$ndias);

}

?>
Saludos