3 responses on “PHP Function Get Previous Twelve Months From Current Month”

After posting this code I realized that when my script gets to a point where I need to query data. I will need to query a month within a specific year and so I extended the $months_past array to include a month and year value per key. Just do date(‘Y’) – 1 within the second foreach to establish the previous year.

That is good actually welcome to WebTechGlobal. What I done was the first thing to cross my my mind and but I must admit. I didn’t consider trying a minus value in any way at all so thanks for that, I best remember to play around with minus more often.

However I’ll run with what I have for a moment as the array is the important part. It will be used in various ways eventually so my approach is to add a lot of values to it now. In risking confusing the post. My use may go back more than 12 months and so I also need to track how far back a month is.