Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/02/2007, 09:42
Avatar de cyberneticos
cyberneticos
 
Fecha de Ingreso: febrero-2007
Ubicación: Pto Sta Mra, Cádiz
Mensajes: 223
Antigüedad: 17 años, 2 meses
Puntos: 3
Re: Restar Fechas

Podrías usar un substring, para pillar el año, mes y día por separado, y utilizar algunas funciones para restar meses, dias y años :

Código:
function getday ($fecha){
	$dia=substr($fecha, 0, 2);
	return $dia;
}

function getmonth ($fecha){
	$mes=substr($fecha, 3, 2);
	return $mes;
}

function getyear ($fecha){
	$year=substr($fecha, 6, 4);
	return $year;
}
y después :

Código:
function retraso ($duedate, $currentdate){
	$yeardifference=getyear($currentdate) - getyear($duedate);
	$monthdifference=getmonth($currentdate) - getmonth($duedate);
	$daydifference=getday($currentdate) - getday($duedate);

	if (  $yeardifference == 0 ){ // same year
		$totaldelay=($monthdifference*30)+$daydifference;
		return $totaldelay;
	}
	else if (  $yeardifference < 0 ){ // negative number
		$totaldelay=($yeardifference * 365)+($monthdifference*30)+$daydifference;
		return $totaldelay;
	}
	else if (  $yeardifference > 0 ){ // positive number
		$totaldelay=($yeardifference * 365)+($monthdifference*30)+$daydifference;
		return $totaldelay;
	}
}
Esto es de un programa que uso para calcular cuantos días de retraso, o adelanto tiene un cliente con respecto a una fecha de caducidad (duedate) y la fecha actual (currentdate)