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!

pad single digit number with leading zero 2

Status
Not open for further replies.

kiwuji

MIS
Apr 9, 2003
16
US
I have a query that retrieve month from database but i want the single digit number to be pad with a leading zero.
this the query
select Month(date()) as [MONTH]
from TABLENAME

currently returns
1 to 9

i want it to return
01 to 09

Thanks,
kiwuji
 
Try this:

iif(Month(date()) < 10, 0 & Month(date()), Month(date())

That is an immediate if statement, and it is checking to see if the month function returns a number less than 10. If it does, it prepends a zero (0) to the month, if not it simply returns the month value. HTH!
 
Thank you so much drtree,
it's working nice

kiwuji
 
How about

Format(Month(date()),&quot;00&quot;)

Then you don't need to bother with the iif.
 
As a generalized solution, where you need to add leading zeroes to MyString to bring it up to MyLength, you can use this:

=String(MyLength-len(MyString),&quot;0&quot;)&MyString
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top