3

help fix this error

Fatal error: Uncaught exception 'Exception' with message 'DateTime::_construct() [datetime.--construct]: Failed to parse time string (--) at position 0 (-): Unexpected character' in Z:\home\plati\www\view.php:110 Stack trace: #0 Z:\home\plati\www\view.php(110): DateTime->_construct('--') #1 {main} thrown in Z:\home\plati\www\view.php on line 110

$newday = $a['dayz'];
$endmonth = $a['monthz'];
$newyear = $a['yearz'];
$date = new DateTime("$newyear-$endmonth-$newday");
$date->modify('+8 day');
$year = $date->format('Y');
$month = $date->format('m');
$day = $date->format('d');

3 Answers 3

3

Have you ever tried printing the value "$newyear-$endmonth-$newday"? Because from the error, it looks like the variables aren't filled with any content. So please post the result of that string.

Sign up to request clarification or add additional context in comments.

Comments

1

help fix this error

You can easily deal with the exception by catching it, this will fix the error in the sense that you don't need to bother about that error any longer:

try {
    $newday = $a['dayz'];
    $endmonth = $a['monthz'];
    $newyear = $a['yearz'];
    $date = new DateTime("$newyear-$endmonth-$newday");
    $date->modify('+8 day');
    $year = $date->format('Y');
    $month = $date->format('m');
    $day = $date->format('d');
} catch(Exception $e) {
    # do nothing
}

At least at some point you need to do error handling. Exceptions require you to do that, DateTime throws exceptions.

Comments

1

The values in $a are empty; check your inputs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.