public static function getSpan( BaseDateTime $date1, BaseDateTime $date2,
        $type = self::SPAN_HOURS, $absolute = TRUE
    )
    {
        $diff = $date1->diff( $date2, $absolute );

        $span = 0;
        
        switch( $type )
        {
            case self::SPAN_YEARS:
                $span = ( int )$diff->y;
                break;
            
            case self::SPAN_MONTHS:
                $span  = $diff->y * 12;
                $span += $diff->m;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_WEEKS:
                $span += $diff->days;
                $span  = ( int )( $span / 7 );
                break;
            
            case self::SPAN_DAYS:
                $span = ( int )$diff->days;
                break;
            
            case self::SPAN_HOURS:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_MINUTES:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( $span * 60 );
                $span += $diff->i;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_SECONDS:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( $span * 60 );
                $span += $diff->i;
                $span  = ( int )( $span * 60 );
                $span += $diff->s;
                break;
            
            default:
                $span = FALSE;
                break;
        }
        
        if ( FALSE === $span )
        {
            return $span;
        }
        
        if ( 1 == $diff->invert )
        {
            return ( $span * -1 );
        }
        
        return $span;
    }
public static function getSpan( BaseDateTime $date1, BaseDateTime $date2,
        $type = self::SPAN_HOURS, $absolute = TRUE
    )
    {
        $diff = $date1->diff( $date2, $absolute );

        $span = 0;
        
        switch( $type )
        {
            case self::SPAN_YEARS:
                $span = ( int )$diff->y;
                break;
            
            case self::SPAN_MONTHS:
                $span  = $diff->y * 12;
                $span += $diff->m;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_WEEKS:
                $span += $diff->days;
                $span  = ( int )( $span / 7 );
                break;
            
            case self::SPAN_DAYS:
                $span = ( int )$diff->days;
                break;
            
            case self::SPAN_HOURS:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_MINUTES:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( $span * 60 );
                $span += $diff->i;
                $span  = ( int )$span;
                break;
            
            case self::SPAN_SECONDS:
                $span  = ( $diff->days * 24 );
                $span += $diff->h;
                $span  = ( $span * 60 );
                $span += $diff->i;
                $span  = ( int )( $span * 60 );
                $span += $diff->s;
                break;
            
            default:
                $span = FALSE;
                break;
        }
        
        if ( FALSE === $span )
        {
            return $span;
        }
        
        if ( 1 == $diff->invert )
        {
            return ( $span * -1 );
        }
        
        return $span;
    }
public static function getSpan ( BaseDateTime $ date1 , BaseDateTime $ date2 , $ type = self :: SPAN_HOURS , $ absolute = TRUE ) { $ diff = $ date1 -> diff ( $ date2 , $ absolute ) ; $ span = 0 ; switch ( $ type ) { case self :: SPAN_YEARS : $ span = ( int ) $ diff -> y ; break ; case self :: SPAN_MONTHS : $ span = $ diff -> y * 12 ; $ span += $ diff -> m ; $ span = ( int ) $ span ; break ; case self :: SPAN_WEEKS : $ span += $ diff -> days ; $ span = ( int ) ( $ span / 7 ) ; break ; case self :: SPAN_DAYS : $ span = ( int ) $ diff -> days ; break ; case self :: SPAN_HOURS : $ span = ( $ diff -> days * 24 ) ; $ span += $ diff -> h ; $ span = ( int ) $ span ; break ; case self :: SPAN_MINUTES : $ span = ( $ diff -> days * 24 ) ; $ span += $ diff -> h ; $ span = ( $ span * 60 ) ; $ span += $ diff -> i ; $ span = ( int ) $ span ; break ; case self :: SPAN_SECONDS : $ span = ( $ diff -> days * 24 ) ; $ span += $ diff -> h ; $ span = ( $ span * 60 ) ; $ span += $ diff -> i ; $ span = ( int ) ( $ span * 60 ) ; $ span += $ diff -> s ; break ; default : $ span = FALSE ; break ; } if ( FALSE === $ span ) { return $ span ; } if ( 1 == $ diff -> invert ) { return ( $ span * - 1 ) ; } return $ span ; }
Returns the span between the two dates.

@param BaseDateTime $date1    first date
@param BaseDateTime $date2    second date
@param string    $type     the scale of span output
[ years, months, days, hours, minutes, seconds ]
@param bool      $absolute should the output be forced to be positive

@return mixed the span between the dates or FALSE on error
Returns the span between the two dates .