src/Common/CodeIgniter/Libraries/FormValidation.php
public function date_before($sDate, $sParams)
    {
        //  If blank, then assume the date is not required
        if (empty($sDate)) {
            return true;
        }

        if (empty($sParams)) {
            return false;
        }

        $aParams = explode('.', $sParams);
        $sField  = !empty($aParams[0]) ? $aParams[0] : null;
        $sFormat = !empty($aParams[1]) ? $aParams[1] : 'Y-m-d';

        if (empty($sField)) {
            return false;
        }

        if (!array_key_exists('date_before', $this->_error_messages)) {
            $this->set_message('date_before', lang('fv_valid_date_before_field'));
        }

        //  If the other field is blank then bail out
        $oInput = Factory::service('Input');
        $sOther = $oInput->post($sField);
        if (empty($sOther)) {
            return false;
        }

        try {

            $oDate  = \DateTime::createFromFormat($sFormat, $sDate);
            $oOther = \DateTime::createFromFormat($sFormat, $sOther);

            if (empty($oDate) || $oOther) {
                return false;
            }

            $oDate->setTime(0, 0, 0);
            $oOther->setTime(0, 0, 0);

            return $oDate < $oOther;

        } catch (\Exception $e) {

            return false;
        }
    }
public function date_before($sDate, $sParams)
    {
        //  If blank, then assume the date is not required
        if (empty($sDate)) {
            return true;
        }

        if (empty($sParams)) {
            return false;
        }

        $aParams = explode('.', $sParams);
        $sField  = !empty($aParams[0]) ? $aParams[0] : null;
        $sFormat = !empty($aParams[1]) ? $aParams[1] : 'Y-m-d';

        if (empty($sField)) {
            return false;
        }

        if (!array_key_exists('date_before', $this->_error_messages)) {
            $this->set_message('date_before', lang('fv_valid_date_before_field'));
        }

        //  If the other field is blank then bail out
        $oInput = Factory::service('Input');
        $sOther = $oInput->post($sField);
        if (empty($sOther)) {
            return false;
        }

        try {

            $oDate  = \DateTime::createFromFormat($sFormat, $sDate);
            $oOther = \DateTime::createFromFormat($sFormat, $sOther);

            if (empty($oDate) || $oOther) {
                return false;
            }

            $oDate->setTime(0, 0, 0);
            $oOther->setTime(0, 0, 0);

            return $oDate < $oOther;

        } catch (\Exception $e) {

            return false;
        }
    }
public function date_before ( $ sDate , $ sParams ) { //  If blank, then assume the date is not required if ( empty ( $ sDate ) ) { return true ; } if ( empty ( $ sParams ) ) { return false ; } $ aParams = explode ( '.' , $ sParams ) ; $ sField = ! empty ( $ aParams [ 0 ] ) ? $ aParams [ 0 ] : null ; $ sFormat = ! empty ( $ aParams [ 1 ] ) ? $ aParams [ 1 ] : 'Y-m-d' ; if ( empty ( $ sField ) ) { return false ; } if ( ! array_key_exists ( 'date_before' , $ this -> _error_messages ) ) { $ this -> set_message ( 'date_before' , lang ( 'fv_valid_date_before_field' ) ) ; } //  If the other field is blank then bail out $ oInput = Factory :: service ( 'Input' ) ; $ sOther = $ oInput -> post ( $ sField ) ; if ( empty ( $ sOther ) ) { return false ; } try { $ oDate = \ DateTime :: createFromFormat ( $ sFormat , $ sDate ) ; $ oOther = \ DateTime :: createFromFormat ( $ sFormat , $ sOther ) ; if ( empty ( $ oDate ) || $ oOther ) { return false ; } $ oDate -> setTime ( 0 , 0 , 0 ) ; $ oOther -> setTime ( 0 , 0 , 0 ) ; return $ oDate < $ oOther ; } catch ( \ Exception $ e ) { return false ; } }
Checks if a date is before another date field

@param string $sDate   The date string to check
@param string $sParams The other field name, and the date format (optional), separated with a period.

@return boolean
Checks if a date is before another date field