user2255811
user2255811

Reputation: 496

Format a date in VBscript to alphanumeric

Is there a way to format a date in vbscript to this: 30-Nov-2013 or even 30-November-2013? I've googled all day and i'm still coming up with nothing.

Upvotes: 1

Views: 813

Answers (3)

seeker
seeker

Reputation: 316

Or using FormatDateTime with vbLongDate (=1).

d = Split(FormatDateTime(Now, 1))
ReDim Preserve d(2)
d = Join(d, "-")
WScript.Echo d

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

An alternative to using DatePart would be the Day, Month and Year functions:

Day(Date) & "-" & MonthName(Month(Date)) & "-" & Year(Date)

Upvotes: 1

Iswanto San
Iswanto San

Reputation: 18569

Try this:

document.write("The current system date is: ")
document.write(DatePart("d", Date) & "-" & MonthName(DatePart("m", Date)) & "-" & DatePart("yyyy", Date) )
document.write(DatePart("d", Date) & "-" & MonthName(DatePart("m", Date), 1) & "-" & DatePart("yyyy", Date) )

Use DatePart to get day, month and year from a date. Use MonthName to get month name.

Upvotes: 2

Related Questions