我需要将数据库中的日期与当天进行比较。这是我的代码,雄辩地说:
$posts = Post::where('date', '=', date('Y-m-d'))->get();
我只想检索今天的帖子。
知道“日期”字段的类型为日期,我该如何使其工作?
我尝试转换date('Y-m-d')
使用“format”方法进行字符串化,但似乎date('Y-m-d')
以某种方式返回布尔值,因此,“format”方法不能应用于它。
我用它来处理我的数据库日期
//Get the database date, and format it
$database_date = date_format($database_date, 'Y-m-d');
//Get today date or another date of you choice
$today_date = new DateTime();
//Format it
$today_date = date_format($today_date, 'Y-m-d');
// Use strtotime() to compare the dates or DateTime::diff for more cleaner IMO
$difference = strtotime($today_date) - strtotime($database_date);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)