Support

Account

Home Forums ACF PRO Compare 2 different time pickers Reply To: Compare 2 different time pickers

  • Hi @zilveer

    You should be able to use the acf/validate_value hook. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acf-validate_value/. It should be something like this:

    add_filter('acf/validate_value/name=time_start', 'my_acf_validate_time', 10, 4);
    
    function my_acf_validate_time( $valid, $first_time, $field, $input ){
        
        // bail early if value is already invalid
        if( !$valid ) {
            
            return $valid;
            
        }
        
        // remove the ":" char from the time and set the value as int
        $first_time = (int) str_replace(':', '', $first_time);
        $second_time = (int) str_replace(':', '', $_POST['acf']['field_588425efcdf00']);
        
        // compare the time
        if( $first_time < $second_time ){
            $valid = 'Start time should be after end date ';
        }
        
        // return
        return $valid;
    }

    I hope this helps 🙂