Support

Account

Home Forums ACF PRO ACF PRO: How to return the DAY from a Date Picker?

Solved

ACF PRO: How to return the DAY from a Date Picker?

  • I’ve just started using ACF Pro. It’s great.

    However, i’ve got a date picker field where on the front end i want to display the DAY and MONTH in separate span tags. Were previously in v4 i would have done something like:

    
    <?php $date = DateTime::createFromFormat('Ymd', get_field('event_date')); ?>
    <span><?php echo $date->format('d'); ?></span>
    <span><?php echo $date->format('M'); ?></span>
    

    However, in v5 this doesn’t seem to work. I understand some things have changed on the date picker function in v5, but not sure how to re-implement this.

    Any input would be great!

  • Your code is working correctly for me.

    Are you sure that you have your date picker returning the date in the Ymd format? (See the attached screenshot of the ACF interface where the return format is set.) You can just echo get_field('event_date') to check the format you’re getting back.

    Alternately, you could do it in procedural style this way, which should work no matter what format is being returned:

    <?php $date = strtotime(get_field('event_date')); ?>
    <span><?php echo date('d', $date); ?></span>
    <span><?php echo date('M', $date); ?></span>
  • My suspicions are confirmed, i’m a complete idiot.

    Cheers for that Matthew… where’s that donate beer/coffee button…

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

The topic ‘ACF PRO: How to return the DAY from a Date Picker?’ is closed to new replies.