Fatal error: throw an exception "Exception" with the message "DateTime ::

Help fix this error

Fatal error: throw an exception "Exception" with the message "DateTime :: _ construct () [datetime .-- construct]: Failed to parse the 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 at 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
source share
3 answers

Help fix this error

You can easily deal with the exception by catching it, this will fix the error in the sense that you no longer need to worry about this error:

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
}

, - . , , DateTime .

+1

- "$newyear-$endmonth-$newday"? - , , - . , , .

+4

$a ; .

+1

All Articles