![](/img/trans.png)
[英]PHP DateTime(): Display a length of time greater than 24 hours but not as days if greater than 24 hours
[英]Eloquent, update all records where hours (time) difference between update_at and current time is greater than 24
我需要更新update_at和當前時間相差大於 24 小時的所有記錄。 實際上,我僅在 24 小時內將業務更新為功能,之后業務將自動取消訂閱功能。 所以我想像這樣更新所有的業務。
Business::where('is_featured', true)
->whereDate('updated_at', '<', now()) // need to calculate difference of 24 hours
->update(['is_featured' => false]);
使用碳,減去 24 小時
Business::where('is_featured', true)
->whereDate('updated_at', '<', now()->subHours(24))
->update(['is_featured' => false]);
或 subDay()
Business::where('is_featured', true)
->whereDate('updated_at', '<', now()->subDay())
->update(['is_featured' => false]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.