select models that more than 24 hours have passed since their creation in laravel
Asked Answered
P

3

-1

I think that question title is Self-Descriptive.

In fact I want to select all rows that more than 24 have passed since their created_at attribute in laravel with Carbon and where clauses.

$question = Question::where('created_at',/* what do I here*/);

How can I do that ?

Premundane answered 22/11, 2016 at 8:53 Comment(1)
Show your code or this question is getting flagged soon.Culbertson
L
4

Try this:

$question = Question::where('created_at', '>=', Carbon::now()->subDay())->get();

Description

Looming answered 22/11, 2016 at 9:4 Comment(1)
I updated question. I want rows that more than 24 hours have passed since their creationPremundane
A
1
$question = Question::where('created_at', date("Y-m-d H:i:s",strtotime("22-11-2016"."-1 day")));
African answered 22/11, 2016 at 9:6 Comment(1)
While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations!Infinity
A
0
Question::where('created_at', '<', now()->subHours(24));
Anting answered 4/7, 2022 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.