Reputation: 171
In my database I have two columns. First is called starting
and the other isending
. Both are formatted like 11:00
. How to get the interval between ending and starting.
I have tried whereBetween
, but it didn't work as I think.
Upvotes: 0
Views: 209
Reputation: 358
you have two methods first you can use double where like
$blablabla= Category::
where('starting','<=','your variable here')
->where('ending','>=','your variable here')
->first();
second method
whereRaw with bindings, where you use the raw condition and a binding for the variable:
whereRaw('? between starting and ending', [$yourVariable])
BOUNCE
wherebetween
is for check the column value between two given values (intervals)
not the opposite you wanna check given value between two columns
Upvotes: 0
Reputation:
You can use Carbon to get the difference, it offers a number of functions for calculating time differences. For example:
$end->diffInSeconds($start);
$end->diffInHours($start);
$end->diffInDays($start);
Those are just a few, see the docs for more examples
Upvotes: 1