Solved

next month number format

Posted on 2011-02-18
3
318 Views
Last Modified: 2012-08-14
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
Comment
Question by:petewinter
3 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 34924885
Try

$nextmonth = sprintf("%02d", date("m")+1 );
0
 
LVL 31

Assisted Solution

by:Zoppo
Zoppo earned 250 total points
ID: 34924889
If you want keep $nextmonth to be a decimal number but just print out '03' you can simply use

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

ZOPPO
0
 

Author Closing Comment

by:petewinter
ID: 34924917
Many thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 26
unset shopping cart session 15 33
How do I change the from header when sending a mail 1 18
Why do people dis php? 5 9
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now