Support

Account

Home Forums General Issues Simply display DAY of the Date Time Picker

Solved

Simply display DAY of the Date Time Picker

  • Hi there,

    I’ve got a date picker field in my Custom Post Type where on the front end I want to display the DAY and MONTH in separate span tags.

    I have tried this code:

    <?php $date = strtotime(get_field('start_datum')); ?>
    <span><?php echo date('d', $date); ?></span>
    <span><?php echo date('M', $date); ?></span>

    What I get as return is “01 Jan” instead of the proper day and month.
    As a test I also used the <?php the_field('start_datum'); ?> code, then the day and month are correctly displayed, but it shows the full date.

    See screenshots for details.

    I am not a PHP coder, so basically, is there a very simple way of just displaying only the DAY and MONTH field?

    I have also attached some screenshots.

    Christel

  • The problem is that the return formatting you have set is not a valid date for use in strtotime(). Set the return formatting as, the 3rd selection ACF gives you is. Alternately you can get the unformulated value from ACF…. I think that this will return the needed timestamp, but I’m not sure so you’ll need to test it.

    
    $date = get_field('start_datum', false, false); ?>
    <span><?php echo date('d', $date); ?></span>
    <span><?php echo date('M', $date); ?></span>
    
  • Hello John,

    Thank you for your reply. I have done what you asked.
    But unfortunately it does not work. It still shows that “01 jan”.

    Regards
    Christel

  • 
    $date = strtotime(get_field('start_datum', false, false)); ?>
    <span><?php echo date('d', $date); ?></span>
    <span><?php echo date('M', $date); ?></span>
    
  • Woohoo! It is working. Thank you for your support.

    Regards
    Christel

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

The topic ‘Simply display DAY of the Date Time Picker’ is closed to new replies.