Solved

next month number format

Posted on 2011-02-18
3
319 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hasing a url 16 24
AWS EC2 & RDS Instance 5 34
Php recording post 4 36
How to change the link of an image using md5 in php ? 3 28
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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

785 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