Home Forums ACF PRO Compare 2 different time pickers


Compare 2 different time pickers

  • Hello,
    I have 2 time pickers fields, where the fields are intendent for meetings.
    There should be a check control just to check that the first time picker cannot be lower then the second time picker when saving a post.

    Any tips and tricks?

  • Hi @zilveer

    You should be able to use the acf/validate_value hook. This page should give you more idea about it: 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 🙂

  • Thanks @james
    I will give it a try 🙂


Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Compare 2 different time pickers’ is closed to new replies.