Level 12
you need to use the class.
<?php namespace App\Http\Controllers;
use DateTime;
use DatePeriod;
use DateIntercal;
class DashboardController extends Controller
{
// your stuff
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys i have some problems with php function. I have script that looks like this:
$format = "Y-m-d";
$begin = new DateTime($startDate);
$end = new DateTime($endDate);
$interval = new DateInterval('P1M');
$dateRange = new DatePeriod($begin, $interval, $end);
$range = [];
foreach ($dateRange as $date) {
$range[] = $date->format($format);
}
but then i put this part of code in controller i get error: FatalErrorException in dashboard_controller.php line 107: Class 'App\Http\Controllers\DateTime' not found
Thanks for help
you need to use the class.
<?php namespace App\Http\Controllers;
use DateTime;
use DatePeriod;
use DateIntercal;
class DashboardController extends Controller
{
// your stuff
}
Please or to participate in this conversation.