function fix
| From: | Andres Baciocco B. | Date: | Tue, 18 Jan 2005 11:45:41 +0000 |
| Subject: | function fix | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-27261@lists.php.net to get a copy of this message | ||
Hi, i have a little contribution to the site
I have detect a function who dont do that it suppost to do
The function dateDiff (linked to date()) return a wrong number, so I have
fixed
And here it is.
function dateDiff($type,$dateTimeBegin,$dateTimeEnd)
{
if($type!="d" && $type!="m" && $type!="y")
{return("..Tipo Inválido");}
$dateTimeBegin = strtotime($dateTimeBegin);
$dateTimeEnd = strtotime($dateTimeEnd);
if($dateTimeBegin === -1) {return("..Fecha Inicio Invalida");}
if($dateTimeEnd === -1) {return("..Fecha Fin Invalida");}
switch($type) //86400 24horas
{
case "d":
$dif=$dateTimeEnd - $dateTimeBegin;
return(floor($dif / 86400));
case "m":
$anosTransc = (date("Y",$dateTimeEnd) - date("Y", $dateTimeBegin))
- 2;
if($anosTransc < 0) $anosTransc = 0;
$mesesTransc= (12 - date("m",$dateTimeBegin)) + date("m",
$dateTimeEnd);
return(($anosTransc*12) + $mesesTransc);
case "y":
$dif = (date("Y",$dateTimeEnd) - date("Y",$dateTimeBegin)) -2;
if($dif < 1) $dif =0;
return $dif;
default:
$dif = $dateTimeEnd - $dateTimeBegin;
return(floor($dif / 86400));
}
}
--
Andrés Baciocco B.
Area Desarrollo Infotecnologías
Facultad de Ingeniería
Universidad de Chile