How to stop changing date & time in acf field (Date Time Picker / WordPress)?

I need to add date & time in an acf field when a user saves a post.
User can only save a post once / Field is Date Time Picker.
The following code adds the date & time when a user saves a post.
The problem is that the time keeps changing to the current time when loading the acf post.
Would you please let me know how to keep the first saving time (stop changing the time)?

Code in functions.php:

add_action('acf/save_post', 'update_submissiondate_field');
function update_submissiondate_field($post_id) {
    
if (get_post_type($post_id) != 'submission') {
return;
}

$current_user = get_current_user_id();
$current_id = get_the_ID();
$args = array(
'posts_per_page'    => -1,
'post_type'         => 'submission',
'author'            => $current_user,
'p'                 => $current_id,
'meta_key'          => 'doc-submit',
'meta_value'        => 'submit'
             );
$query = new WP_Query($args);
//  echo 'Post';
    if ($query->have_posts()) {
//echo 'Have Post1';
    global $post;
        while ($query->have_posts()) {
        $query->the_post();
            
        $field_key = "field_60c2d9e889989";
        $value = current_datetime();
        update_field($field_key, $value, $post->ID); 
        }   
         wp_reset_postdata();
     } else {return;}
}


Thank you.

Read more here: https://stackoverflow.com/questions/67943496/how-to-stop-changing-date-time-in-acf-field-date-time-picker-wordpress

Content Attribution

This content was originally published by Fioi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: