Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keeping zero in variable 1

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
0
0
BE
hi,

I'm working on a script that uses a calendar... for that, I have variable like $m, $d, $y to represent month, day and year... But apparently php just throws the zero away, and I need the zero later in the script...
so if I were to say:
$d = "02";
$m = "02";
$y = "2002";

and I would like to print that:
print ("$d$m$y");
I would get 222002
But I really need 02022002...

I hope you understand what I mean...
with date() you can actually leave the zero's out of it:
m - month; i.e. "01" to "12"
n - month without leading zeros; i.e. "1" to "12"

And I use the 'm' when I get the date... but the zero is just gone...

Can anyone help?
Thanx,
math

 
You can just reformat your numbers to make the date you need.
Code:
$d = "02";
$m = "02";
$y = "2002";
print(date("mdY", mktime(0,0,0,$m,$d,$y)));
Hope that works for you!
 
You can use the [tt]printf[/tt] formatting codes to do just that.

I hope it works...
Unix was made by and for smart people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top