我创建它是为了比较时间,现在与表行executes_at中的时间相同。
$dateNow = Carbon::now()->format('Y-m-d');
$hourNow = Carbon::now()->format('H');
$minuteNow = Carbon::now()->format('i');
$recordings = Recording::with('therapy')
->where(DB::raw("DATE_FORMAT(executes_at,'%Y-%m-%d')"), '=', $dateNow)
->where(DB::raw("DATE_FORMAT(executes_at,'%H')"), '=', $hourNow)
->where(DB::raw("DATE_FORMAT(executes_at,'%i')"), '=', $minuteNow)
->get();它在MySQL中有效,但是由于我们现在使用的是PostgreSQL,所以我有一个错误
SQLSTATE42883:未定义函数:7错误:函数date_format(日期未知)不存在
有人能帮我做这个吗。
发布于 2019-10-03 08:07:17
这可以简化。只需生成正确的日期时间格式(不分分钟),并使用DATE_TRUNC()对其进行比较:
$dateNowToMinute = Carbon::now()->format('Y-m-d H:i');
$recordings = Recording::with('therapy')
->where(DB::raw("DATE_TRUNC('minute', executes_at)"), '=', $dateNowToMinute)
->get();https://stackoverflow.com/questions/58214778
复制相似问题