Try using the DATE() function to extract the date from datetime. If you are using MySQL.
$orders = DB::select('SELECT DATE(created_at) as stat_day, SUM(billing_totalprice) from Orders GROUP BY DATE(created_at) ORDER BY stat_day;');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need only date from created_at column for DB RAW query:
$orders = DB::select('SELECT created_at as stat_day, SUM(billing_totalprice) from Orders GROUP BY created_at order by stat_day;');
Try using the DATE() function to extract the date from datetime. If you are using MySQL.
$orders = DB::select('SELECT DATE(created_at) as stat_day, SUM(billing_totalprice) from Orders GROUP BY DATE(created_at) ORDER BY stat_day;');
Please or to participate in this conversation.