This topic is locked

Date Formatting

9/14/2007 5:33:50 PM
ASPRunnerPro General questions
J
JOHNF777 author

I'm trying to format the current date to YYYYMM format to be stored in a number field as a Default.
Example: today's date of 9/14/2007 to 200709.
Anyone know how I can do this?
I've tried something like: cstr(YEAR(NOW)) & cstr(MONTH(NOW)) but I'm not sure how I can format the months 1-9 with a leading zero.
Thanks.

Sergey Kornilov admin 9/14/2007

Try something like this:

CStr(YEAR(NOW)) & iif (MONTH(NOW)<10, "0", "" ) & CStr(MONTH(NOW))
J
JOHNF777 author 9/17/2007

Sergey, there's no VBScript for IIF.
But I found a solution.....
I created a function IIF and added the lines below to commonfunctions.asp:
function Iif(expr, truepart, falsepart)

IIf = falsepart

If expr Then IIf = truepart

end function
Now it works!
Thanks for pointing me to my solution... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=21434&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
JohnF

Sergey Kornilov admin 9/17/2007

Johnf,
thanks! We used to have this function in older version of ASPRunnerPro.

I'll add it back.