Reputation: 55
I have a table that consists of a column named created_at
. Whenever I dump this specific column, it returns as a Carbon object as below:
I've coded this query to get data from the said table based on date. Code is as below:
$date = $this->request->get('date');
$orders = Order::where( 'created_at', $date )->get();
$date
is retrieved from the url and the format is 'Y-m-d'
making it impossible to query properly since 'created_at'
and $date
is not in the same format. How can I get date from the Carbon object in 'Y-m-d'
format and insert it in my query?
Upvotes: 0
Views: 1661
Reputation: 123
This should do the job
$date = $date->toDateString();
Or just
$date = $date->format("Y-m-d");
Upvotes: 0
Reputation: 1413
if $date
is in format Y-m-d
you can use whereDate
like this
$orders = Order::whereDate( 'created_at', $date )->get();
Upvotes: 5