#Custom Start DATE

4 messages · Page 1 of 1 (latest)

rich wharf
#

How to make custom START DATE where begin from July not January.

This code return month as per january until december :

for ($i = 1; $i <= 12; $i++) {
  $cashTransactions = $this->model->select('amount', 'paid_on')
  ->whereMonth('paid_on', "{$i}")
  ->whereYear('paid_on', date('Y'))
  ->sum('amount');

  $results[$months[$i - 1]] = $cashTransactions;
}

I wanna make custom start date for that.
How to achieve that ?

pliant fable
#

lazy version:

foreach ([7,8,9,10,11,12,1,2,3,4,5,6] as $i) {
    //
}

to make it flexible you can use the modulo operrator

pulsar orchid
#
for ($i = $startMonth; $i <= 12; $i++) {
  $cashTransactions = $this->model->select('amount', 'paid_on')
  ->whereMonth('paid_on', "{$i}")
  ->whereYear('paid_on', date('Y'))
  ->sum('amount');

  $results[$months[$i - 1]] = $cashTransactions;
}

Replace the start value of $i could work if you're just looking to go from x to december

rich wharf