Anyone could help me? I have the following fatal error: uncaught error: call to a member function format on string on line 89;
the line 89 is
$monday->setISODate($days->format("o"),$days->format("W"));
my function is:
function dateToWeekPeriod($days)
{
$monday = new DateTime();
$monday->setISODate($days->format("o"),$days->format("W"));
$sunday = clone $monday;
$sunday->modify("+6 day")->setTime(23,59);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($monday, $interval, $sunday);
return $period;
}
my function main is:
function main()
{
$end = new DateTime("now");
$begin= clone $end;
$begin->modify('-50 days')->setTime(23,59);
echo $end->format('Y-m-d'), "\n", $begin->format('Y-m-d')."\n";
$interval= new DateInterval('P1D');
$daterange= new DatePeriod($begin, $interval, $end->modify("+1 day"));
$days=array();
foreach($daterange as $date)
{
$date->format('Y-m-d')."\n";
array_push($days,$date->format('Y-m-d'));
}
echo "-----les dates de l'intervalle sont:-----\n";
var_dump($days);
$Week=array();
$datas=array();
$Weeks=array();
$insertAnnee=array();
$recupAnnee=array();
$tabRecupAnneeDesc=array();
foreach($days as $d)
{
$week = periodToDayArray(dateToWeekPeriod($d));//les jours de la semaine concernée
$Week=array_push($Week,$week);
}
I have got a stack trace on this line:
$week = periodToDayArray(dateToWeekPeriod($d))
thanks in advance
In your main function, $days
is a string array. You pass an element (string) of this array into the dateToWeekPeriod
function.
$monday->setISODate($days->format("o"),$days->format("W"));
$days->format("o") // not possible
The easiest way is to keep $days
on the date.
$days=array();
foreach($daterange as $date)
{
array_push($days,$date);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.