Date function to display the date as mm / dd / yy

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?

+3
source share
4 answers

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()
+5
source

One line alternative that does not require .NET:

d = Right("0" & Month(Date), 2) & "/" & Right("0" & Day(Date), 2) & "/" & Right(Year(Date), 2)
+2
source

Formatting formats is FormatDateTime and returns a valid date:

FormatDateTime(date,2)
+1
source

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
0
source

All Articles