Hi Guys, I was hoping to be able to determine the current month and then output the previous month.
//returns current month as a single number, in this case 6 (june)
echo date('n');
If I reduce that by 1;
//the number is now 5 and I would like to output the month in full (may)
$newdate = date('n')-1;
How do I now out put the month in Full using 5??
Sorry if this is a completely silly question.
You know the answer to your own question. You know that the line "echo date('n')" prints out "6" for June. Well, use a the mktime() and date() functions to print it out.
<?php echo date("F", mktime(0,0,0,date('n')-1,date('j'),date('Y')); ?>
[man]mktime/man [man]date/man
~Brett
Thanks heaps, I knew what I needed but did not know how to code it.
Cheers
Or (and this will probably involve less processing)
$months = array(1=>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); echo $months[5];
Or (maybe the easiest):
$last_month = date('F', strtotime('-1 month'));