我在DB中有一个DATETIME类型的列,并且是格式yyyy-mm-dd hh:mm:ss。然而,作为信息,我得到的只是日期(我不在乎时间)。那么,即使值同时包含日期和时间,我应该如何查询DB以按日期搜索该列?
更新:
下面是我试图选择实体的PHP代码:
public static function getTripsWithDrivers($route_from = null, $route_to = null, $date = null)
{
$trips = Trip::whereRouteFrom($route_from)->whereRouteTo($route_to)->whereStartDate($date);
...
}发布于 2015-04-06 10:46:02
使用MySql 日期函数:
$trips = Trip::where(DB::raw('DATE(route_from)'), '=', $route_from)
->where(DB::raw('DATE(route_to)'), '=', $route_to)
->where(DB::raw('DATE(start_date)'), '=', $date)发布于 2015-04-06 10:45:56
用户where过滤器如下:
WHERE "datetime column" like '2015-04-06%'https://stackoverflow.com/questions/29469689
复制相似问题