Trying to get the number of the month before of the current month

The currently accepted response will result in an incorrect answer whenever the day of the month (for the current day) is a larger number than the last day of the month for the previous month.

e.g. The result of executing date('m', strtotime('-1 month')); on March 29th (in a non-leap-year) will be 03, because 29 is larger than any day of the month for February, and thus strtotime('-1 month') will actually return March 1st.

Instead, use the following:

date('n') - 1;

The correct way to do this really is:

date('m', strtotime('-1 month'));

As you will see strange things happen in January with other answers.

Tags:

Php

Date