skaisser
1476
2
Eloquent

[WhereBetween] - Retrieve Data between Two Dates from Timestamp Column

Posted 3 years ago by skaisser

Hello Guys.

Im having trouble to retrieve data from the database using eloquent, I am trying to retrieve all data between two dates (created_at field).

I've Done This:

 public function    __construct()
        {
            $this->datai = Carbon::now()->subDays(3);
            $this->dataf = Carbon::now();
        }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    { 
        $dataInicio = $this->datai->format('Y-m-d')." 00:00:00";
        $dataFim    = $this->datai->format('Y-m-d')." 23:59:59";
        $pedidos = DB::table('pedidos')
                    ->whereBetween('created_at', [$dataInicio, $dataFim])->get();
    }

I Don't Think it is a smart way to do this, maybe i am missing something, Could you please help?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.