• Resolved Deepak Chauhan

    (@deepchauhan)


    Hi,
    I am getting an error when I add this code to get the event month. Please help me how I can resolve this issue.
    Error is : Uncaught Exception: DateTime::__construct(): Failed to parse time string (23/07/2020) at position 0 (2):

    Code Which I am using :

    <?php
      eventDate = new DateTime(get_field('event_date'));
      echo $eventDate->format('M')
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Deepak Chauhan

    (@deepchauhan)

    Hi,
    I have fixed the issue just add this code below.

    // get raw date
    $date = get_field('event_date', false, false);
    // make date object
    $date = new DateTime($date);
    echo $date->format('M');

    I hope this will help you all.

    Thank You

    Thanks bro this code helped me.

    Thank you bro, you was very useful

    cupidanish10

    (@cupidanish10)

    Hi can anyone explain the code why this was not working. Is it work for 1 day?
    I mean i added 2 posts yesterday and this code was working fine. But today I added new and this is not working.
    <?php
    eventDate = new DateTime(get_field(‘event_date’));
    echo $eventDate->format(‘M’)
    ?>

    and this is working fine how?
    // get raw date
    $date = get_field(‘event_date’, false, false);
    // make date object
    $date = new DateTime($date);
    echo $date->format(‘M’);`

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

The topic ‘Uncaught Exception: DateTime::__construct(): Failed to parse time string’ is closed to new replies.