【发布时间】:2016-05-06 12:09:40
【问题描述】:
我有一个表格,它为用户收集简单的日期时间和日期时间。
我正在使用 laravel 输出 indate_time 在特定日期范围之间的行。
From Date: 2016/01/28
To Date: 2016/01/28
我的表中的示例条目
ID | indate_time | outdate_time
1 | 2016-01-28 21:22:49 | 2016-01-28 21:46:05
目前我没有得到回应这是我的 laravel 查询
$from = '2016/01/28';
$to = '2016/01/28';
$id = 1;
$attendance = DB::table('attendances')
->whereBetween('indate_time', array($from, $to))->where('id', $id)->orderBy('indate_time', 'desc')
->get();
【问题讨论】:
-
您的新日期时间将得到
2016-01-28 00:00:00那么indate_time怎么能介于两者之间呢? -
您在比较日期时间值,而不仅仅是日期。如果您只关心日期,那么您需要明确告诉 mysql。因为
2016-01-28 23:59:59是同一个日期,但在特定时间范围之外。 -
谢谢@MarcB 我将如何为 laravel 查询指定超出日期时间的日期?对不起
-
$from = new \DateTime("now"); $to = new \DateTime("now"); $to->setTime(23, 59, 59);
标签: php laravel laravel-5 eloquent