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

displaying month as two digits 3

Status
Not open for further replies.

eljacobs

Programmer
Oct 13, 2003
47
0
0
GB
Hi

Does anyone kwow of a way to display the month as two digits in ASP vb?

i.e.

i need september to display as '09' not '9','SEP','September' etc.

Thanks

Elliot
 
try this:

mymonth="00"&month(now)
response.write Right(mymonth,2)

-DNG
 
Thats great thanks.

One question though. What will happen when the month reaches double fugures? i.e. will october display as 10 or 010?
 
The right() function here takes the last 2 digits - and as you are adding the two 00 chars on the left you will always get what you want...

"00" = "00" ->> right("00",2) = "00" '//this is unlikely to happen.
"00" & "1" = "001" ->> right("001",2) = "01"
"00" & "11" = "0011" ->> right("0011",2) = "11"
"00" & "111" = "00111" ->> right("00111",2) = "11" '/// this will not happen with months

you're slicing and dicing at an absolute point in the string based on the count of digits from the right.

More information on right()

A smile is worth a thousand kind words. So smile, it's easy! :)
 
great replies DotNetGnat, damber and FesterSXS. Clear, precise and well explained.

Thanks for your help.

Elliot
 

No problem, good luck with your project

A smile is worth a thousand kind words. So smile, it's easy! :)
 
glad to be of help...i hope you got the little trick we used here to get two digits...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top