next month number format

I am using the below code to get next month

$nextmonth = date("m")+1;

echo $nextmonth;

So currently prints "3"

How can I make it print as 03 instead of 3 only if the result is a single number i.e. 0 to 9 not 10 to 12?
petewinterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Beverley PortlockConnect With a Mentor Commented:
Try

$nextmonth = sprintf("%02d", date("m")+1 );
0
 
ZoppoConnect With a Mentor Commented:
If you want keep $nextmonth to be a decimal number but just print out '03' you can simply use

printf( "%02d", $nextmonth );

ZOPPO
0
 
petewinterAuthor Commented:
Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.