Delete Elequent records older than 60 minutes
How can I delete all Eloquent Records in a database where the created_at or updated_at field is older than 60 minutes? (or any amount of time for the example)
edit: posted solution as answer as @Alexxus suggested
database laravel-4 eloquent
add a comment |
How can I delete all Eloquent Records in a database where the created_at or updated_at field is older than 60 minutes? (or any amount of time for the example)
edit: posted solution as answer as @Alexxus suggested
database laravel-4 eloquent
2
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16
add a comment |
How can I delete all Eloquent Records in a database where the created_at or updated_at field is older than 60 minutes? (or any amount of time for the example)
edit: posted solution as answer as @Alexxus suggested
database laravel-4 eloquent
How can I delete all Eloquent Records in a database where the created_at or updated_at field is older than 60 minutes? (or any amount of time for the example)
edit: posted solution as answer as @Alexxus suggested
database laravel-4 eloquent
database laravel-4 eloquent
edited Nov 18 '18 at 14:06
Barry127
asked Jun 16 '14 at 18:29
Barry127Barry127
7731619
7731619
2
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16
add a comment |
2
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16
2
2
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16
add a comment |
1 Answer
1
active
oldest
votes
Solved -> With ceejayoz his link
- Make a date object and minus the amount of time.
- Covert the date object to string to match Eloquent formatting
- Compare formatted string against updated_at
I'm using the following code:
$date = new DateTime;
$date->modify('-60 minutes');
$formatted = $date->format('Y-m-d H:i:s');
MyModel::where('updated_at', '<=', $formatted)->delete();
Thanks ceejayoz!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24249923%2fdelete-elequent-records-older-than-60-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solved -> With ceejayoz his link
- Make a date object and minus the amount of time.
- Covert the date object to string to match Eloquent formatting
- Compare formatted string against updated_at
I'm using the following code:
$date = new DateTime;
$date->modify('-60 minutes');
$formatted = $date->format('Y-m-d H:i:s');
MyModel::where('updated_at', '<=', $formatted)->delete();
Thanks ceejayoz!
add a comment |
Solved -> With ceejayoz his link
- Make a date object and minus the amount of time.
- Covert the date object to string to match Eloquent formatting
- Compare formatted string against updated_at
I'm using the following code:
$date = new DateTime;
$date->modify('-60 minutes');
$formatted = $date->format('Y-m-d H:i:s');
MyModel::where('updated_at', '<=', $formatted)->delete();
Thanks ceejayoz!
add a comment |
Solved -> With ceejayoz his link
- Make a date object and minus the amount of time.
- Covert the date object to string to match Eloquent formatting
- Compare formatted string against updated_at
I'm using the following code:
$date = new DateTime;
$date->modify('-60 minutes');
$formatted = $date->format('Y-m-d H:i:s');
MyModel::where('updated_at', '<=', $formatted)->delete();
Thanks ceejayoz!
Solved -> With ceejayoz his link
- Make a date object and minus the amount of time.
- Covert the date object to string to match Eloquent formatting
- Compare formatted string against updated_at
I'm using the following code:
$date = new DateTime;
$date->modify('-60 minutes');
$formatted = $date->format('Y-m-d H:i:s');
MyModel::where('updated_at', '<=', $formatted)->delete();
Thanks ceejayoz!
answered Nov 18 '18 at 14:05
Barry127Barry127
7731619
7731619
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24249923%2fdelete-elequent-records-older-than-60-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
possible duplicate of Laravel select records older than 5 minutes?
– ceejayoz
Jun 16 '14 at 18:38
I would start by learning the MySQL date/time functions dev.mysql.com/doc/refman/5.5/en/….
– Dave
Jun 16 '14 at 18:48
Please post the aswer as answer
– Alexxus
Oct 30 '18 at 6:16