Reputation: 2953
I have an Eloquent query that currently looks like this:
$rides = Ride::where('date', '>=', new \DateTime('today'))
->where('date', '<=', new \DateTime('tomorrow'))
->get();
Which works fine, my question is, how do I go about formatting it like so:
$rides = Ride::where('date', '>=', new \DateTime('tomorrow'))
->where('date', '<=', new \DateTime('tomorrow + one'))
->get();
Meaning I am trying to find the results whose dates are between tomorrow and the day after tomorrow. Any help would be greatly appreciated.
Upvotes: 11
Views: 19625
Reputation: 417
new \DateTime('tomorrow + 1day')
It's OK if you are not interested in hours and minutes.. It's gives you always midnigth but
$dayAfterTomorrow = (new \DateTime())->add(new \DateInterval('P2D'));
gives you exactly 2 days from now and hours and minutes are kept
Upvotes: 4
Reputation: 18440
The day after tomorrow is two days from now, so this will work:-
$dayAfterTomorrow = (new \DateTime())->add(new \DateInterval('P2D'));
Upvotes: 2
Reputation: 157947
If you want to get the day after tomorrow you can use:
new \DateTime('tomorrow + 1day')
You can find more information in the manual page 'Relative time formats'
Upvotes: 35