Support

Account

Home Forums General Issues Date format output

Solving

Date format output

  • Hi,
    I have a ACF Field with datepicker and like to display the date in this format:
    <b>10</b><br>Feb

    Wordpress get_date can do this format with a code like this:
    $output .= get_the_date('<\b/>d<\/b/><\b\r/>M');

    Is there something similar with ACF?

  • It depends on what version of ACF you’re using. There is a custom format for the display formatting. In ACF4 it says you can use any valid jquery date format. For ACF5 it uses the builtin WP function date_i18n() https://developer.wordpress.org/reference/functions/date_i18n/ and you can use any valid date formatting string.

    If this does not work for you then you’ll need to get the unformatted value of the field get_field('field_name', false, false); and format it yourself using PHP.

  • Hi John,
    thanks for your answer! With your hints I figured it out. This is my solution:

    $date = get_post_meta( $entry->ID, "my-acf-field", true );
    $date = new DateTime($date);
    $finalVal =  $date->format('<\b/>j<\/b/><\b\r/>M'); 
    $output .= $finalVal;
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Date format output’ is closed to new replies.