Support

Account

Home Forums Backend Issues (wp-admin) date & time picker "NOW" issue

Solving

date & time picker "NOW" issue

  • Hi

    i was trying to have “NOW” date & time to be auto display without the needs to click on “NOW”.

    i was giving this piece of code but unfortunately it did not do the job:

    —————————————

    add_filter(‘acf/load_field/name=YOUR_DATE_FIELD’, ‘my_acf_default_date’);

    function my_acf_default_date($field) {

    $field[‘default_value’] = date(‘Y-m-d H:i:s’);

    return $field;
    }
    ——————————————–

    example:

    my Sydney Australia current time / desktop time was: 11/09/2019 1:11 AM

    on the sites ACF datepicker i get : 10/09/ 3:11 PM

    thanks

  • Try

    
    $field['default_value'] = date('Ymd');
    
  • Hi

    thanks for the help, i did insert bellow but still no good:

    add_filter(‘acf/load_field/name=publishing_date’, ‘my_acf_default_date’);

    function my_acf_default_date($field) {

    $field[‘default_value’] = date(‘Ymd’);

    return $field;
    }

    it shows:
    September 15, 2019 12:00 am

    where it is on my desktop:

    September 16, 2019 03:20 am

    regards

  • I looked into the code, the date field does not work with setting $field['default_value']. You need to use this https://www.advancedcustomfields.com/resources/javascript-api/#filters-date_picker_args

    I do not know the correct code you need to use here to set the date, you will need to look at the jquery date picker docs here https://api.jqueryui.com/datepicker/

  • Hi John

    it is being a long time since your last reply

    we have tried a different date and time picker but unfortunately it did not works as it should.

    now back to ACF date & time picker.

    we have installed the bellow code but again, we still having a problem with current time.

    example:

    we create a post at :19/09/2020 12:49 am

    but on the date & time picker it is: 18/09/2020 2:49 pm

    even so, the developer is completely lost and can not figure out what to do no more.

    any help would be much appreciated.

    the code:

    add_action( ‘acf/save_post’, ‘set_submit_time’ );
    function set_submit_time($post_id) {
    update_field(‘entry_post_date’, date(‘Y-m-d H:i:s’), $post_id);
    }

    add_action(‘save_post’, ‘change_content’);
    global $post;
    global $wpdb;
    function change_content($post_id) {
    $datefield = get_post_meta($post_id,’entry_post_date’,true);
    $post_date = date(“Y-m-d H:i:s”, strtotime($datefield));
    $my_post = array();
    $my_post[‘ID’] = $post_id;
    $my_post[‘post_date’] = $post_date;

    remove_action(‘save_post’, ‘change_content’);
    wp_update_post( $my_post );
    add_action(‘save_post’, ‘change_content’);
    }

    add_filter(‘acf/load_field/name=entry_post_date’, ‘my_acf_default_date’);

    function my_acf_default_date($field) {

    $field[‘default_value’] = date(‘Y-m-d H:i:s’);

    return $field;
    }

  • Looking back at your OP I may have originally misunderstood your problem.

    With your original code was the default date time not set or was the default date time incorrect?

    I’m not really sure why you’d be using save_post and acf/save_post here unless you want this field to always be reset to the current time when a post is updated.

  • Hi

    “With your original code was the default date time not set or was the default date time incorrect?”

    – we have lost the old original code

    —————————-

    for the second part of your reply, i don’t really know.
    the developer become blank and could not work out what to do next.

    let me clear something first:

    – server time and location are correct

    what is happen now is this:

    – when adding new post, date & time picker display wrong date & time (14 hours behind)

    – if i click on “NOW” it display the correct current date & time, but when i click on “publish”, date & time back wrong again (14 hours behind).

    all we needs is this:

    when adding new post, date & time picker is to display correct (our current) date & time without the needs of click on “NOW”, also to keep (our current) date & time after publishing the post.

    thanks

  • Hi

    in addition to my previous post, here a clear video screenshots of what is going on:

    http://www.alankabout.com.au/date-and-time-picker.mp4

    as you can see, my desktop time was “19/09/2020 11.23 AM” where on the date & time picker it was “19/09/2020 1.23 AM”

    date & time picker is 10 hours behind my desktop (my current time in Sydney, Australia).

    hope the video helps

    thanks

  • I honestly do not know why this is happening. Please check this topic, it’s the only thing that I can think of that might be causing the issue https://support.advancedcustomfields.com/forums/topic/date-picker-fields-in-repeaters-gone-wrong-after-wp-5-3-update/

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

The topic ‘date & time picker "NOW" issue’ is closed to new replies.