Good afternoon. To display statistics you need to get a list of the last 6 and 12 months from the current inclusive. I tried:

for($i = 11;$i > -1;$i--){ $m = $i*30; $index = date('Ym',strtotime('-'.$i.' days',strtotime("today"))); } 

But since the months are not always 30 days, the list will be inaccurate in the last days of the month. Who can faced a similar problem and knows how to solve?

    1 answer 1

    You can do the following:

     <?php for($i = 11, $time = time(); $i > -1; $i--, $time -= date('t', $time) * 86400){ $index = date('Ym', $time); }