Show your DB query
Aug 19, 2021
8
Level 1
How to compare Timestamp field with Date values. (MYSQL)
I want to get the data between 2 dates. My query is working in the mysql. but for some reason not working in the laravel DB raw query.
My this query where data is static works in the laravel DB RAW and i get the data.
$profit_data = DB::select("SELECT
job.name,
sum(job_payments.payments) AS total_pay,
From job_payments
LEFT JOIN job on job.id = job_payments.job_id
WHERE
job.code= 2 AND job.status = 'ended'
AND (DATE(job .start_date) BETWEEN '2021-08-17' AND '2021-08-17' )
GROUP BY
job.status");
My this query doesn't work when i put the $variables instead of static date. I get no error, but the result i get is empty when i use variables for dates.
$start_date = $request->start_date;
$end_date = $request->end_date;
$start_date = date('Y-m-d', strtotime($start_date));
$end_date = date('Y-m-d', strtotime($end_date));
$profit_data = DB::select("SELECT
job.name,
sum(job_payments.payments) AS total_pay,
From job_payments
LEFT JOIN job on job.id = job_payments.job_id
WHERE
job.code= 2 AND job.status = 'ended'
AND (DATE(job.start_date) BETWEEN $start_date AND $end_date )
GROUP BY
job.status");
Please or to participate in this conversation.