Is there any simple way of getting the month in 2 digit format when using the month function? e.g. I type month(now) and it returns 8, not 08. Is it possible to change this default setting or do I have to use an if statement to determine if it's one digit or two and add a 0 if its one? Or even better, is there a way to format date in yyyy-mm-dd that I have missed? Just thinking there should be an easier way. //Anders
sure. code below will do both jobs for ya in one fell swoop. dim zmonth, zdate, zyear, zdateformat zmonth = cstr(month(now)) zdate = cstr(date(now)) zyear = cstr(year(now)) if len(zmonth) = 1 then zmonth = "0" & zmonth end if if len(zdate) = 1 then zdate= "0" & zdate end if zdateformat = zyear & "-" & zmonth & "-" & zdate response.write zdateformat Code (markup):
Thanks, it's a bit shorter than my code, byt was just thinking if there was a way to do it without the "if"s, seems a bit unnessecary to me that you can't get it directly out of the date string
if statement is good. But without if .... you may use Loop code: For i=1 to ezerLength - Len(sString) sString="0"&sString next source code from: http://3w.ezer.com/asp/time/now.asp#example_code
how about response.write(right$("0" & month(now()),2)) the Right$("0" & Month(Now()), 2) is what you want
I was curious about this and tried it out myself - couldnt get it to work. I played around with the "right" function and made a slight modification to burgerking's code - (and by slight, i mean i deleted one character - LOL) and got it to work right by using this: right("0" & month(now()),2) it is hands down a far more elegant solution than mine, and i'll be using it myself from now on in similar coding situations. kudos burgerking! VG
The right$ is for vb.net & vb6 - not sure about asp - sorry for asp.net you can also use strings.right Glad you like the solution