Support

Account

Home Forums General Issues Print date in another format than the one stored?

Helping

Print date in another format than the one stored?

  • I am using DatePicker fields to date posts with the save format yymmdd (e.g., ‘20170103’). In the loop I can then sort all posts according to date. I find that using a different date format (e.g., D’ ‘d’ ‘MM) messes up the sorting so I feel constrained to using this format for saving in the database.

    However, on the generated web pages, I would like to echo the dates using a different format, e.g., 3 Jan (yes, without the year) instead of 20170103.

    What I have now in the loop is:
    $date = get_field( 'event_date' ); followed by
    echo '<div>' . $date . '</div>';

    I look at examples of strtotime in order to transform “$date” but am not sure how to craft it for my purpose and if at all it is the best approach to what I want to achieve.

    I would be very greatful for some help with how to do this.
    Thanks!

  • Hi @pastic

    Did you use ACF free version? If you did, I believe you can set the display format from the setting page. I’ve attached a screenshot for your reference.

    If you want to use the strtotime() function but don’t know how to do it, the best place to ask it is to PHP community. Please take a look at this thread to learn more about it: http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php.

    I hope this helps 🙂

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

The topic ‘Print date in another format than the one stored?’ is closed to new replies.