【问题标题】:Eloquent: get only the date from timestampEloquent:仅从时间戳中获取日期
【发布时间】:2017-06-05 07:07:05
【问题描述】:

我想为用户获取特定日期的所有条目。我不知道如何格式化查询。

public function getEntry()
{
    $entries = Journal::where('id', '=', Auth::id())
    ->where('created_at', '=', '\Carbon\Carbon::now()->format("l j F Y")')
    ->get()->first();
    return view('home')->with(compact('entries'));
}

我不知道如何格式化“created_at”以匹配服务器时间。任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: php mysql laravel eloquent timestamp


    【解决方案1】:

    使用whereDate() 获取特定日期的所有条目:

    ->whereDate('created_at', Carbon::today());
    

    或使用whereBetween():

    ->whereBetween('created_at', [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()])
    

    或者简单的where():

    ->where('created_at', '>', Carbon::now()->startOfDay())
    ->where('created_at', '<', Carbon::now()->endOfDay())
    

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多