Solved

next month number format

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 …

856 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