YouTip LogoYouTip

Func Formatdatetime

# VBScript FormatDateTime Function * * Complete VBScript Reference Manual](#) * * * The FormatDateTime function formats and returns a valid date or time expression. ### Syntax FormatDateTime(date,format) | Parameter | Description | | :--- | :--- | | date | Required. Any valid date expression (e.g., Date() or Now()). | | format | Optional. A format value specifying the date/time format to use. Possible values are: * 0 = vbGeneralDate - Default. Returns date: mm/dd/yy and, if time is specified: hh:mm:ss PM/AM. * 1 = vbLongDate - Returns date: weekday, monthname, year * 2 = vbShortDate - Returns date: mm/dd/yy * 3 = vbLongTime - Returns time: hh:mm:ss PM/AM * 4 = vbShortTime - Returns time: hh:mm | ## Example ## Example Display the date in different formats: d=CDate("2010-02-16 13:45") document.write(FormatDateTime(d) & "
") document.write(FormatDateTime(d,1) & "
") document.write(FormatDateTime(d,2) & "
") document.write(FormatDateTime(d,3) & "
") document.write(FormatDateTime(d,4) & "
") Output of the above example: 2/16/2010 1:45:00 PM Tuesday, February 16, 2010 2/16/2010 1:45:00 PM 13:45 [Try it yourself Β»](#) * * Complete VBScript Reference Manual](#)
← Func HourFunc Day β†’