Re: function fix
| From: | Gabor Hojtsy | Date: | Wed, 19 Jan 2005 11:58:46 +0000 |
| Subject: | Re: function fix | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-27280@lists.php.net to get a copy of this message | ||
Hi Andres,
We have a user contribution system, where you can submit your notes. Please submit this there.
Goba
Hi, i have a little contribution to the site I have detect a function who don’t 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));} }