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!

Date format in vbscript for outlook form

Status
Not open for further replies.

lywong111

Programmer
Apr 4, 2004
13
US
Hi,

I would like to display date in a textfield in the format 'yyyymmdd'.
If I use:
strGetDate=CStr(Year(InvoiceDate) & Month(InvoiceDate) & Day(InvoiceDate))

It gives me yyyymd. Tried use formatDate but it says type mismatch.

Any ideas how to do it??

Thanks in advance
 
strGetDate=CStr(Year(InvoiceDate) & right$("00"+Month(InvoiceDate),2) & right$("00"+Day(InvoiceDate)),2)


should work

:)
 
Hi docjohn52,

Your code doesnt work in my outlook form.
I'm using vbscript in my outlook form to achieve that scenerio, and outlook doesnt regconise the $ sign.

Anyway, thanks for the help.

Any alternatives you can think of?
 
strGetDate=CStr(Year(InvoiceDate) & right$("00"+Month(InvoiceDate),2) & right$("00"+Day(InvoiceDate)),2)... ummmm

This is the "Formal" method for full-blown VB, try just

strGetDate=CStr(Year(InvoiceDate) & right("00"+Month(InvoiceDate),2) & right("00"+Day(InvoiceDate)),2)

You should cruise...

this is a no-brainer, fixing date fields is a stanrd Micro-Shaft function. You do see what it does? Just adds a zero basically...to two fields...

failing this send me the code and i'll fix it...

 
Have you tried this ?
strGetDate=Year(InvoiceDate) & Right("0" & Month(InvoiceDate),2) & Right("0" & Day(InvoiceDate),2)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi both,

Thanks so much for helping

PHV: Your code works! I just copy and paste into my code and it works fine now. Thanks.

docjohn: Guess ur's couldnt work might be due to the "00".Anyway, U'vr also provided a good start-off. Thanks too!!
 
docjohn: Guess ur's couldnt work might be due to the "00".
I don't think so. I guess the problem is with the + operator instead of &.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
phv,

You're right, the + operator works in standard vb...

sorry...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top