Sosumi
Sosumi

Reputation: 779

How to get the next month in PHP?

I'm currently using the following code to calculate the next month:

$nextMonth = date("m",strtotime("+1 months"));

If the current date is March 31 (03), this code gives me "05" which is actually 2 months away from the current date. I would like it to return April (04) instead.

How can I achieve this?

Upvotes: 0

Views: 453

Answers (1)

Dinesh
Dinesh

Reputation: 3105

how about trying this:

$d = new DateTime(date("Y-m-d"));
$d->modify( 'first day of next month' );
echo $d->format( 'F' ), "\n";

Dins

Upvotes: 1

Related Questions