Laravel SQLSTATE[42883]:未定义函数:7错误:函数日期\格式(日期,未知)不存在

Laravel SQLSTATE[42883]:未定义函数:7错误:函数日期\格式(日期,未知)不存在,laravel,postgresql,pg-query,Laravel,Postgresql,Pg Query,我创建它是为了比较现在的时间与表行中的时间相同 $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,

我创建它是为了比较现在的时间与表行中的时间相同

$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,所以我有这个错误

SQLSTATE[42883]:未定义函数:7错误:函数 日期\格式(日期,未知)不存在


有人能帮我吗。

这可以简化。只需生成正确的日期时间格式(不含分钟),并使用
DATE\u TRUNC()
进行比较:

$dateNowToMinute = Carbon::now()->format('Y-m-d H:i');
$recordings = Recording::with('therapy')
    ->where(DB::raw("DATE_TRUNC('minute', executes_at)"), '=', $dateNowToMinute)
    ->get();

不要使用
date\u格式
尝试使用
to\u char
例如:
to\u char(now(),'YYYY-MM-DD')
,格式参考:谢谢,我刚刚更改了这个
'Y-m-d H:I'
,效果很好。