简体   繁体   中英

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.

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.

使用DatePart的另一种方法是DayMonthYear函数:

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

Or using FormatDateTime with vbLongDate (=1).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM