EV43G‖FormatDateTime Function [VBA]

Contents
qBmWV‖

# ioqgs‖FormatDateTime Function [VBA]

EFKxm‖Applies a date and/or time format to a date expression and returns the result as a string.

R9TFi‖This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.

### FVEx2‖Syntax:

            FormatDateTime (Date As Date [, NamedFormat As Integer])

### bBBqF‖Return type:

String

### WADQ4‖Parameters:

APZJw‖Date: The date expression to be formatted.

WC3h8‖NamedFormat: An optional vbDateTimeFormat enumeration specifying the format that is to be applied to the date and time expression. If omitted, the value vbGeneralDate is used.

### 9KCAo‖Date and Time formats (vbDateTimeFormat enumeration)

THiYn‖Named Constant | AoBxM‖Value | TtduL‖Description
--- | --- | ---
vbGeneralDate | 0 | G67rA‖Displays a date and/or time as defined in your system's General Date setting. If a date only, no time is displayed; If a time only, no date is displayed.
vbLongDate | 1 | DgHi6‖Display a date using the long date format specified in your computer's regional settings.
vbShortDate | 2 | qEzCP‖Display a date using the short date format specified in your computer's regional settings.
vbLongTime | 3 | PdzuG‖Displays a time as defined in your system's Long Time settings.
vbShortTime | 4 | TJciz‖Display a time using the 24-hour format (hh:mm).

### SEjHR‖Error codes:

13 Data type mismatch

### EFSA4‖Example:

            REM  *****  BASIC  *****
            Option VBASupport 1
            Sub DateFormat
             Dim d as Date
             d = ("1958-01-29 00:25")
            GicVB‖ msgbox("General date format : " & FormatDateTime(d))
            sERMj‖ msgbox("Long date format : " & FormatDateTime(d,vbLongDate))
            aG8eg‖ msgbox("Short date format : " & FormatDateTime(d,vbShortDate))
            EpGjV‖ msgbox("Long time format : " & FormatDateTime(d,3))
            zt2KQ‖ msgbox("Short time format : " & FormatDateTime(d,vbShortTime))
            End Sub

Related Topics

VBA Time and Date functions

Please support us!