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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Insert Leading 0 to Current Month

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
hi experts,

If I use the month function, it returns a single digit (for months 1 thru 9).

I need to get it to a 2 digit value.
If I have : curMonth = month() I get a value of 1

How can I insert a leading zero to get a value of '01' ?

Pretty simple stuff but I'm stumped.
Thanks, John
 
Code:
select right('00'+cast(1as varchar),2)

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
This would also work.

Select convert(varchar(2), GetDate(), 101)
 
I messed up - should have posted this question in the VBscript forum.

My apologies for wasting your time.
John
 
its ok I probably would have wasted it myself anyway ! :)

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top