phpbar.de logo

Mailinglisten-Archive

[php] Zeitabfrage

[php] Zeitabfrage

Zobel M. zobel at hnw-online.de
Mon Mar 22 13:33:04 CET 2004


Hallo,

/**
* Berechnet Anzahl der Tage zwischen 2 Datumswerten
*
*/
function count_days($start, $end)
{
sm('count_days');
   if( $start != '0000-00-00' and $end != '0000-00-00' )
   {
       $timestamp_start = strtotime($start);
       $timestamp_end = strtotime($end);
      if( $timestamp_start >= $timestamp_end ) return 0;
      $start_year = date("Y",$timestamp_start);
       $end_year = date("Y", $timestamp_end);
       $num_days_start = date("z",strtotime($start));
       $num_days_end = date("z", strtotime($end));
       $num_days = 0;
      $i = 0;
       if( $end_year > $start_year )
       {
         while( $i < ( $end_year - $start_year ) )
          {
            $num_days = $num_days + date("z", strtotime(($start_year + $i)."-12-31"));
             $i++;
          }
       }
       cm('count_days');
        return ( $num_days_end + $num_days ) - $num_days_start;
   }
   else
   {
   cm('count_days');
        return 0;
   }
}

/**
* Berechnet Anzahl der Monate zwischen 2 Datumswerten
*
*/
function count_months($in_dateLow, $in_dateHigh)
{
sm('count_months');
   if( $start != '0000-00-00' and $end != '0000-00-00' )
   {
       $in_dateLow = strtotime($in_dateLow);
       $in_dateHigh = strtotime($in_dateHigh);

   if ($in_dateLow > $in_dateHigh) {
       $tmp = $in_dateLow;
       $in_dateLow = $in_dateHigh;
       $in_dateHigh = $tmp;
   }

   $dateLow = $in_dateLow;
   $dateHigh = $in_dateHigh;
  $periodDiff = 0;
   while ($dateLow < $dateHigh) {
       $periodDiff++;
       $dateLow = strtotime('+1 month',$dateLow);
   }
   cm('count_months');
   return $periodDiff-1;
   }
   else
   {
    cm('count_months');
        return 0;
   }
}

mfg

Michel Zobel 
Software Entwicklung / Softwaredevelopement
health network




php::bar PHP Wiki   -   Listenarchive