PHP DateTime help

Hello,

I inherited a website that I am helping run for a club. It uses PHPBB and Wordpress. We migrated it to a online hosting service. We got everything working except for one single part of the site. The error involves Date time. Here is the general error. There is more two it and it points to other files but the gyst of the error is this

Fatal error: Uncaught exception ‘Exception’ with message ‘DateTime::__construct(): Failed to parse time string (5) at position 0 (5): Unexpected character’ in /home1/gmdgcorg/public_html/wp-content/themes/HorseRacing/sidebar.php:51 Stack trace: #0 /home1/gmdgcorg/public_html/wp-content/themes/HorseRacing/sidebar.php(51): DateTime->__construct(‘5’) #1

Here is the line of code its complaining about

  • <?php $tdate = get_field('tournament_date'); $date = new DateTime($tdate); echo $date->format('M d, Y'); $days = get_field('multi-day'); if ($days[0] == '2-day') { date_add($date, date_interval_create_from_date_string('1 day')); echo ' - '; echo $date->format('M d, Y'); } ?> <?php the_title(); ?>
  • Again if you need anymore info please ask. I appreciate any help you can give me and I am sorry if this is not the proper forum for this question

    Thanks!

    Do you know the stored value of, tournament_date?

    You may have to parse it.

    Here’s the code properly formatted to make it easier to see and debug?

    [php]

  • <?php
    $tdate = get_field(‘tournament_date’);
    $date = new DateTime($tdate);
    echo $date->format(‘M d, Y’);
    $days = get_field(‘multi-day’);
    if ($days[0] == ‘2-day’) {
    date_add($date, date_interval_create_from_date_string(‘1 day’));
    echo ’ - ';
    echo $date->format(‘M d, Y’);
    }
    ?>
    <?php the_title(); ?>
  • [/php]

    Put a
    [php]echo “

    ” . print_r($tdate, 1) . “
    ”; [/php]
    after the $tdate variable like astonecipher stated.
    Sponsor our Newsletter | Privacy Policy | Terms of Service