Support

Account

Home Forums General Issues Format of date picker elements

Solved

Format of date picker elements

  • I created a date (i.e. date picker) field (event_date) using ACF. I’m using a query to fetch posts (events) after today’s date e.g. event_date>=date('Ymd) seems to work, pls ignore the syntax for brevity sake.

    When I look at the date format for event_date it’s format is dd/mm/yyyy as confirmed by the output of: echo get_field('event_date'); so is this being determined by the Return Format – The format returned via template functions option which I set when creating the ACF?

    If so, why then when I run the query in WP_Query with
    event_date>=date('dmY) my query fails to work correctly.
    event_date>=date('Ymd) my query works correctly.
    Again pls ignore the syntax for brevity sake.

    Can I also ask regarding the following get_field('event_date', false, false), with the second boolean parameter if it’s set to true where is the formatting defined?

  • Hi GusGF,
    I’ve used date formatting like this:

    $startmulti = get_sub_field('start_date_1', false, false);
     $startmulti = new DateTime($startmulti);

    and then in then in my output
    $startmulti->format('F j')

    This has always worked for me to set the format of the datepicker.

  • Well I’m wondering if when you query from the database an ACF date or any date, then it’s in the default WP database format of ‘Ymd’.

    Yes @rociopts that’s how I use date as well in my code.

    Still wondering about this…

    Can I also ask regarding the following get_field(‘event_date’, false, false), with the second boolean parameter if it’s set to true where is the formatting defined?

  • Date fields are always stored in the DB in the format “Ymd”. The format returned when using get_field() is determined by the setting for return format.

    The default for the third parameter is true, meaning to format the value, as determined by the field settings. setting it to false returns the unformatted value as stored in the database.

  • @hube2 Thank you for confirming that.

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

You must be logged in to reply to this topic.