View Full Version : php to get previous month's name?


fourthring
11-19-2004, 11:10 AM
Hi I know there is probably a thousand ways to do this but is there a quick way using the date() function to find the last month's full name?

$today = getdate();
$month = $today['month'];

or

$month= date('F');

This would give me 'November' for this month but how do I get the previous month's name?

I know I coud just make an array with all the names of all the months and subtract one but I dont' want to have to deal with the problem when a new year rolls around. Right now I have a hack and it just checks to see if the month numeral is equal to 0 (january) then subtract from 12 to get 11 (december).but I was wondering if there is a cleaner way that this?

Thanks

l3vi
11-25-2004, 02:09 AM
Yep,

$month = date("F", mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));

Enjoy!