Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving strtotime() expects parameter 1 to be string, object given error in php

Tags:

date

php

laravel

The program works fine when I pass the array like following:

$holidays=array("2015-01-01","2015-01-05","2015-01-10");

echo getWorkingDays("2015-01-02","2015-01-09",$holidays);

But when I extract the data from database like this:

$holidays = DB::table('tbl_holiday')->select('holiday_date')->whereBetween('holiday_date', array('2015-01-01', '2015-01-20'))->get();

I am getting this error: strtotime() expects parameter 1 to be string, object given

In my helpers.php, I have this code

 foreach($holidays as $holiday){

       $time_stamp=strtotime($holiday);

      //If the holiday doesn't fall in weekend
      if ($startDate <= $time_stamp && $time_stamp <= $endDate && date("N",$time_stamp) != 6 )
      $workingDays--;
}

Any help would be appreciated.

like image 543
user3127109 Avatar asked Sep 04 '25 16:09

user3127109


1 Answers

Just get the actual datestring from $holiday

$timestamp = strtotime($holiday->holiday_date);
like image 183
lukasgeiter Avatar answered Sep 07 '25 14:09

lukasgeiter