Support

Account

Home Forums Backend Issues (wp-admin) Calculate PHP date_diff and save to ACF Field during post creation Reply To: Calculate PHP date_diff and save to ACF Field during post creation

  • Hmm, something like:

    <?php
    
    $now = time(); 
    
    $date_created = $order->get_date_created();
    
    $dt = new DateTime($date_created);
    
    $date = $dt->format('Y-m-d');
    
    $your_date = strtotime($date);
    $datediff = $now - $your_date;
    
    $diff = round($datediff / (60 * 60 * 24));
    
    update_post_meta( $post_id, 'custom_field', $diff );

    Amend custom_field to your field name, code untested