Support

Account

Home Forums General Issues Calculating time in ACF Reply To: Calculating time in ACF

  • SOLVED

    `function calculated_field_value() {
    // Get field values (these will be updated in real-time)
    $starttime = af_get_field( ‘consultation_start_time’ );
    $endtime = af_get_field( ‘consultation_end_time’ );

    // Calculate the sum of the current field values
    $starttimestamp = strtotime($starttime);
    $endtimestamp = strtotime($endtime);
    $difference = abs($endtimestamp – $starttimestamp)/3600;

    // Display the sum in the calculated field
    return $difference . ‘hrs<br><small>NB – Number is a decimal of hours and minutes</small>’;
    }
    add_filter( ‘af/field/calculate_value/name=total_duration’, ‘calculated_field_value’, 10, 0 );