Reputation: 3763
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.
Upvotes: 4
Views: 12199
Reputation: 62308
Using the database query, your $holidays
variable is an array of stdClass objects. If you want an array that contains just the holiday_date
values, you can use the lists()
method, instead of get()
:
$holidays = DB::table('tbl_holiday')
->whereBetween('holiday_date', array('2015-01-01', '2015-01-20'))
->lists('holiday_date');
Upvotes: 3
Reputation: 152950
Just get the actual datestring from $holiday
$timestamp = strtotime($holiday->holiday_date);
Upvotes: 3