[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

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?
0
petewinter
Asked:
petewinter
2 Solutions
 
Beverley PortlockCommented:
Try

$nextmonth = sprintf("%02d", date("m")+1 );
0
 
ZoppoCommented:
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now