How to convert mm/dd/yyyy date format to yyyy-mm-dd

M

masani paresh

Hi Friends,

Could anyone please tell me how I can convert mm/dd/yyyy date format to
yyyy-mm-dd in VBScript.

Thanks,
Megha
 
K

Ken Slovak - [MVP - Outlook]

Use the Format() function. If your date is myDate then Format(myDate,
"yyyy-mm-dd")
 
M

masani paresh

Hey Ken,

I am using this function with my outlook project. But it gives the error
message saying "Variable is undefined Format" in following line.

MsgBox DateValue(Item.Start) & " " & Format(Item.Start,"yyyy-mm-dd")

Thanks,
Paresh
 
M

masani paresh

Hi Ken, I got the solution. We need to add following function in the code.
Thanks for you initial reply.

Function Format(vExpression, sFormat)
set fmt = CreateObject("MSSTDFMT.StdDataFormat")
fmt.Format = sFormat

set rs = CreateObject("ADODB.Recordset")
rs.Fields.Append "fldExpression", 12 ' adVariant

rs.Open
rs.AddNew

set rs("fldExpression").DataFormat = fmt
rs("fldExpression").Value = vExpression

Format = rs("fldExpression").Value

rs.close: Set rs = Nothing: Set fmt = Nothing
End Function


Thanks,
Paresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top