gpt4 book ai didi

php - 如何在 laravel 中使用 mysql DATE_SUB?

转载 作者:行者123 更新时间:2023-11-30 21:56:38 24 4
gpt4 key购买 nike

如何在 laravel 中使用 mysql date_sub 方法?在 laravel 中,我想使用 date_sub 获取时间属性的值。我尝试了下面的代码,但我什么也得不到。

$notAllowedTime = DB::table('consultant_timings')
->where('id',78,DB::raw('DATE_SUB(time2,INTERVAL 30 MINUTE'));

最佳答案

你必须使用 whereRaw 来做到这一点

这样试试

$notAllowedTime = DB::table('consultant_timings')
->whereRaw('id =78 AND DATE_SUB(time2,INTERVAL 30 MINUTE'));

修改:-根据你的描述(评论)你想在 30 分钟内检索值(value)然后你可以这样做

$notAllowedTime = DB::table('consultant_timings')
->select(['*',DB::raw("DATE_SUB($time2,INTERVAL 30 MINUTE) as time2")])
->where('id','=',82)
->get();

关于php - 如何在 laravel 中使用 mysql DATE_SUB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com