Support

Account

Home Forums General Issues Date Field not displaying

Solved

Date Field not displaying

  • Hi All,

    Where am I making am mistake displaying “$departure_date->format(‘j M Y’)”

    $departure_date = get_field('departure_date', false, false);
    $departure_date = new DateTime($departure_date); 
    $cruise_line = get_field('cruise_line');
    $ship = get_field('ship');
    
    if(get_field('ship'))
    {
        echo 'Departs' . $departure_date->format('j M Y') . get_field('cruise_line') . ' | ' . get_field('ship');
    
    }
  • Hi @greycam ,

    Looking at your code, the implementation seems just fine.

    Kindly check to ensure that the value returned by the get_field is in the correct format.

    You may do a var_dump() of the same to check.

    Let me know how it goes.

  • So I changed my code around

    It now looks like this

    $departure_date = get_field('departure_date', false, false);
    $departure_date = new DateTime($departure_date); 
    <?php echo $depature_date->format('j M Y'); ?>

    It now displays the date “Departs 9 Jan 2017” even if the date is set to Jun 1, 2017

    When I do $date on it’s own I get: 20170601

  • Hi @greycam

    Could you please make sure that you were debugging the correct variables?

    Could you please try the following code:

    $departure_date = get_field('departure_date', false, false);
    $departure_date = new DateTime($departure_date);
    
    echo "\nderpature_date: \n" . $departure_date;
    echo "\nformatted derpature_date: \n" . $departure_date->format('j M Y');

    Thanks 🙂

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

The topic ‘Date Field not displaying’ is closed to new replies.