Home Forums Feature Requests Option to format Date & Time pickers from the core WordPress options. Reply To: Option to format Date & Time pickers from the core WordPress options.

  • Interesting solution.

    If I was going to to this I would just ignore the settings for the fields. I would then create 2 filter.

    The first would be an acf/prepare_field filter. In this filter I would alter the display format and simply set all date and date/tie fields the WP format.

    The second filter would be an acf/format_value filter with a priority > 10 so that it runs after the ACF built in filter. Here I would call this with the WP date format value

    return acf_format_date( $value, 'your_format_here');

    This could also be used in conjunction with your custom setting if you did not want to do this for all date fields, but if I was going to do this it would all be the same.

    Actually to be honest, I set all date field return values to ‘Y-m-d’ and all date time fields to ‘Y-m-d H:i:s’ because I generally custom code all date display on the front end to meet client needs and those needs usually mean that I’ll be showing dates differently depending on where they will be shown. For example an event might actually show something like June 1 to June 4, 2021 (start and end dates) and this cannot be achieved without additional coding. These return formats are the easiest to use when custom formatting dates and easy enough to change.

    echo date('whatever format I want', strtotime(get_field('my-date-field')));

    So I would only concern myself with the acf/prepare_field filter.

    As an added note. Using the acf/prepare_field filter is usually always better than the acf/load_field filter. For example, in the field group editor if you edit the field group the load field filter could effect the field when editing it and you’ll need to set it back to your custom value every time you edit the group unless you conditionally alter the field based on the post type being loaded. It can also effect how the field is saved in local JSON and when exporting or importing a field group. So you’ll want to watch out for that.