Home Forums Backend Issues (wp-admin) Error tying to format date


Error tying to format date

  • hello i am having this error
    Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (30/11/2018) at position 0 (3): Unexpected character in /app/public/wp-content/themes/scai/front-page.php:87 Stack trace: #0 /app/public/wp-content/themes/scai/front-page.php(87): DateTime->__construct('30/11/2018') #1 /app/public/wp-includes/template-loader.php(74): include('/app/public/wp-...') #2 /app/public/wp-blog-header.php(19): require_once('/app/public/wp-...') #3 /app/public/index.php(17): require('/app/public/wp-...') #4 {main} thrown in /app/public/wp-content/themes/scai/front-page.php on line 87

    when try to format date

    Here is the code generating the error

      $eventDate = new DateTime (get_field('event_date'));
      echo $eventDate -> format('y');
  • Hi – I wonder whether you ever solved this issue. I have the same error. I have diagnosed that this only happens if the day value is greater than 12. Obviously this is a format issue but on the Event edit screen it shows correctly. If I set the date to say 12 July everything is cool but my code returns the 7th December. If I change it to 13 July it falls over – as there is no 13th month.

    My WP general setting is set to GMT

    The relevant code is:

    $eventDate = new DateTime(get_Field(‘event_date’));
    echo $eventDate->format(‘M’)
    <span class=”event-summary__day”><?php echo $eventDate->format(‘d’) ?>

    Any help gratefully received

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

You must be logged in to reply to this topic.