【问题标题】:Laravel using Carbon::today how to get date value from a datetime field?Laravel 使用 Carbon::today 如何从日期时间字段中获取日期值?
【发布时间】:2021-01-13 11:18:24
【问题描述】:

这是我的控制器代码。如何从日期时间字段中获取日期值?

public function UserContentShowDateList(){
'usercontents'=>UserContent::where('status',1 )->where('date', Carbon::today())->get()
}

【问题讨论】:

    标签: php laravel date datetime


    【解决方案1】:
    UserContent::where('status',1 )->where(DB::raw('DATE(date)'), Carbon::today())->get();
    

    我认为这将有助于仅从日期时间字段中获取日期。

    【讨论】:

      【解决方案2】:

      你可以使用 whereDate

      UserContent::where('status',1 )->whereDate('date', today())->get();
      

      将日期字段添加到模型中的 $dates 属性。

      protected $dates = ['date'];
      

      【讨论】:

        猜你喜欢
        • 2016-02-24
        • 2017-09-24
        • 2015-09-28
        • 2017-07-06
        • 2011-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多