Leading zeros - the easy way
Most web developers will say you have to do all these IF statements and what-not just to get a zero in front of a number. Example, I want an 8 digit date (mmddyyyy). ASP will only generate a single digit “1″ for January and a single digit “1″ for the first. This means I end up with 112007. Not good. Here’s a sample to solve this problem :
<%
str= “1″
str=right(”00″ & str, 2) // returns “01″
%>
Perfect! What this is doing is adding 00 to str, so it then becomes “001″, then it takes the two right-most characters. Returning “01″. This is good because if you have a two digit day or month, then the two right-most characters are the two digits of that day or month. Bam! Easy huh?