Reputation: 12512
I need to write a simple loop routine to show 24 months back starting with today's month. How would I do that?
$start = date(M) - 24;
$end = date(M);
foreach() {
echo ''; // Dec, Jan...
}
Upvotes: 1
Views: 364
Reputation: 34053
Something like this should work:
for($i = 1; $i <= 24; $i++) {
echo date("M", strtotime("-$i months")) . "\n";
}
Result
Feb Jan Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan Dec Nov Oct Sep Aug Jul Jun May Apr Mar
Upvotes: 3
Reputation:
for ($i = 1; $i <= 24; $i++) {
$months[] = date("Y-m%", strtotime( date( 'Y-m-01' )." -$i months"));
}
or for full textual representation of month you need to pass "F":
echo date("y:F:d");
for previous month you can use
echo date("y:F:d",strtotime("-24 Months"))
Upvotes: 1