I have 2 separate columns for the date: the date
itself in YYYY-mm-dd
format, and a time
column in time(7)
datatype, for example 11:15:10.0000000
How can I check for rows that are in the future?
I can get the first part, for the day itself:
MyModel::where('date', '>=', Carbon::today())->get()
But when I try adding the time it doesn’t work:
MyModel::where('date', '>=', Carbon::today())->where('time', '>', Carbon::now()->format('H:i'))->get()
because they are separate and now even though the date is in the future, the time is separate so there may be a situation where the time doesn’t match. So I somehow need to have both the date and the time related to it in the future, not separately
2
Answers
Try to combine both the columns in a single condition.
For SQL Server try following
Query conversion may need to update, for more information try documentation
Comparison via datatype is important here. So, you can use
orWhere
to combine 2 different conditions. For this, you will need to pass a callback to group conditions inside one for the AND in where conditions in raw format.