I am trying to get a date in mm / dd / yy format using VB Script.
But I could not find any function to fulfill this requirement, can someone help me here, please?
I like to use the .NET stringbuilder because I can switch between formats on the fly by simply adapting the format specifier instead of using string manipulations:
wscript.echo CreateObject("system.text.stringbuilder").AppendFormat("{0:MM}/{0:dd}/{0:yy}", now).ToString()
One line alternative that does not require .NET:
d = Right("0" & Month(Date), 2) & "/" & Right("0" & Day(Date), 2) & "/" & Right(Year(Date), 2)
Formatting formats is FormatDateTime and returns a valid date:
FormatDateTime(date,2)
For local independent formatting:
function mmddyyyy(input) dim m: m = month(input) dim d: d = day(input) if (m < 10) then m = "0" & m if (d < 10) then d = "0" & d mmddyyyy = m & "/" & d & "/" & right(year(input), 2) end function