0

How to calculate the amount between 2 dates. For example Consider if in month January 2021 I need to get the amount between From Date: 1st Jan 2021 and To Date : `15 Jan 2021. The calculation should be = Total Amount - (Amount from 16 Jan to 31 Jan)

Hope for a guidance to solve this :)

Daryl
  • 1
  • 2
  • https://stackoverflow.com/questions/39508963/calculate-difference-between-two-dates-using-carbon-and-blade take a look this – Kamlesh Paul Dec 30 '20 at 04:14
  • I assume that you will calculate amount from the database, then you should use whereBetween https://stackoverflow.com/questions/33361628/how-to-query-between-two-dates-using-laravel-and-eloquent – Anurat Chapanond Dec 30 '20 at 04:22

2 Answers2

0

Use whereBetween... Try:

$date1 = date('2021-01-01');
$date2 = date('2021-01-15');
    
Your_Model::whereBetween('date_col', [$date1, $date2])
    ->select( DB::raw('SUM(your_col) as amount'))
    ->get();
0
$date1 = 1st Jan 2021 //formate upto you, standard format 2021-01-01
$date2 = 15 Jan 2021 //formate upto you, standard format 2021-01-15

$total_amount = $date1->diff($date2);

Or follow this,

Finding days between two dates in laravel

I hope it will be work!