Home Forums Front-end Issues Date format


Date format

  • Hello!
    I’m having trouble with date formatting.
    I enter the code indicated in the Documentation of the ACF, but does not appear the date selected internally only the current date, today.

    I have already tried with the following two codes and the same for both:

    <?php $dateformatstring = "d/m/Y";
    $unixtimestamp = strtotime(get_field('desde'));
    echo date_i18n($dateformatstring, $unixtimestamp);?>
    <?php $date = get_field('desde', false, false); 
    $date = new DateTime($date);?>
    <p>Event start date: <?php echo $date->format('j M Y'); ?></p>

    Result of both:

    What am I doing wrong?
    How do I get the date chosen on beckend?

    Thank you!


  • Hmm, have you altered the default date format for this field? The default “yymmdd” should be working fine in your code sample.

    Try echoing the raw value that get_field() returns, without parsing it with strtotime(), to see what’s up with it.

  • Hello, @stormwind!

    Thank you for your return.
    I already got it.
    The problem was in get_field, I changed to get_sub_field and that’s it and ready the date selected appears as it would be.
    Silly thing. rsrsrs

    Thank you so much

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

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