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
Laravel have a build in Carbon date class which handles all the timezone problems for you.
Example:
$date = Carbon::now()->subMinutes( 60 );
MyModel::where( 'updated_at', '<=', $date )->delete();
Solved -> With ceejayoz his link
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With