Php 如何使用';日期添加';在Laravel连接中的功能?
我有一个Laravel 4连接,如下所示:Php 如何使用';日期添加';在Laravel连接中的功能?,php,sql,join,laravel-4,laravel-query-builder,Php,Sql,Join,Laravel 4,Laravel Query Builder,我有一个Laravel 4连接,如下所示: return DB::table(Location::getTableName() . ' as l')->where('l.company_id', $companyId) ->join(User::getTableName() . ' as u', 'u.location_id', '=', 'l.id')->whereIn('l.id', $locationsId) ->join(UserT
return DB::table(Location::getTableName() . ' as l')->where('l.company_id', $companyId)
->join(User::getTableName() . ' as u', 'u.location_id', '=', 'l.id')->whereIn('l.id', $locationsId)
->join(UserTimeline::getTableName() . ' as ut', 'ut.user_id', '=', 'u.id')
->join(Status::getTableName() . ' as s', 's.id', '=', 'ut.status_id')
->select(
'l.name as location_name',
'u.first_name as user_first_name',
'u.last_name as user_last_name',
'u.email as user_email',
'ut.started_at as timeline_started_at',
'ut.finished_at as timeline_finished_at',
's.id as status_id',
's.label as status_label'
)
->orderBy('ut.id', 'asc')
->skip($from)
->limit($limit)
->get();
我必须检测用户的时区,并将与格林尼治标准时间的差值计算为一个数字,巴基斯坦为+5,印度为+5.5。
现在我的问题是,我正在将此联接的数据导出到CSV文件中。我必须在“时间线开始时间”和“时间线结束时间”中添加小时数。我搜索并发现SQL的“DATEADD”方法可以增加或减少小时数
真正的问题是,我不知道在上面的连接中,我应该在我的Laravel连接中使用'DATEADD'函数
有人能在这方面帮助我吗????您可以使用它向查询中添加sql函数
例如:
$test = DB::table('test')->where(DB::raw('DATE_ADD(created_at, 5)'), '<', $date)->get();
$test=DB::table('test')->其中(DB::raw('DATE_ADD(created_at,5)”),您可以使用类似以下内容:
return DB::table(Location::getTableName() . ' as l')->where('l.company_id', $companyId)
->join(User::getTableName() . ' as u', 'u.location_id', '=', 'l.id')->whereIn('l.id', $locationsId)
->join(UserTimeline::getTableName() . ' as ut', 'ut.user_id', '=', 'u.id')
->join(Status::getTableName() . ' as s', 's.id', '=', 'ut.status_id')
->select(
'l.name as location_name',
'u.first_name as user_first_name',
'u.last_name as user_last_name',
'u.email as user_email',
'DATE_ADD(ut.started_at, INTERVAL '.$var.' HOUR) as timeline_started_at',
'DATE_ADD(ut.finished_at, INTERVAL '.$var.' HOUR) as timeline_finished_at',
's.id as status_id',
's.label as status_label'
)
->orderBy('ut.id', 'asc')
->skip($from)
->limit($limit)
->get();
其中,$var
表示小时数。给出错误:SQLSTATE[42S22]:未找到列:1054未知列“日期”添加(ut.started在“字段列表”中”(SQL:选择l
name
作为location\u name
,u
first\u name
作为user\u first\u name
,u
作为user\u last\u name
,u
email
作为user\u email
,“………..请尝试添加数据库侦听器并转储吗执行的SQL?我不知道如何执行DB Listner,还有什么要做的?它不是在listener中转储查询,只是给出错误。如果我转储任何其他查询,它会工作,但对这个查询也不工作。您是否删除$var并只键入一个静态数字DATE\u ADD(ut.started\u,间隔5小时)