note 98143 deleted from function.date-diff by danbrown

From: Date: Tue, 01 Jun 2010 15:00:47 +0000
Subject: note 98143 deleted from function.date-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169807@lists.php.net to get a copy of this message
Note Submitter: djmib at djmib dot net ---- Other Example: PS: $strTipo = Type of return (s= second | m= minute | h= hour | D= days). $strDataIni = Start Date of interval. $strDataFim = End Date of interval. The date is in format yyyymmdd -> 99991231 or text "now" to indicate now. function dataDiferenca($strTipo, $strDataIni, $strDataFim){ if($strDataIni!="now"){ if(!checkdate( substr($strDataIni,4,2), substr($strDataIni,6,2), substr($strDataIni,0,4))){ return false; } } if($strDataFim!="now"){ if(!checkdate( substr($strDataFim,4,2), substr($strDataFim,6,2), substr($strDataFim,0,4))){ return false; } } $data = date("U",strtotime($strDataFim)) - date("U",strtotime($strDataIni)); if($strDataIni=="now"&&$strDataFim!="now"&&date("I")){ $data += 3600; }else if($strDataIni!="now"&&$strDataFim=="now"&&date("I")){ $data -= 3600; } $arrData = array( "s" => $data, "m" => floor($data / 60), "h" => floor($data / 60 / 60), "D" => floor($data / 60 / 60 / 24) ); return (is_null($arrData[$strTipo]))?0:$arrData[$strTipo]; }

« previous php.notes (#169807) next »