Support

Account

Home Forums General Issues Returning date output

Helping

Returning date output

  • The following outputs the date_picker just fine so long as there is a value entered.

    
    <?php if(get_field('start_date')): ?>
    <?php $date = DateTime::createFromFormat('m/d/Y', get_field('start_date')); ?>
    <?php echo '<div class="meta"><span class="time">Starts: ' . $date->format('F j, Y') . '</span></div>'; ?>
    <?php endif; ?>
    

    Otherwise, it throws an error immediately after the first post that doesn’t have a value for the date_picker field. Why is that?

  • Hi @spinline

    It should not bring about any error. The logic in your code is correct.

    Hmm… You need to echo the value of get_field('start_date') when the date_picker field does have a value to find out what it returns. In your case, it seems to be returning something.

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

The topic ‘Returning date output’ is closed to new replies.