Returns an expression formatted as a date or time.
Function FormatDateTime( ByVal Expression As DateTime, Optional ByVal NamedFormat As DateFormat = DateFormat.GeneralDate ) As String
The NamedFormat argument has the following settings:
Constant | Description |
---|---|
DateFormat.GeneralDate | Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed. |
DateFormat.LongDate | Display a date using the long date format specified in your computer's regional settings. |
DateFormat.ShortDate | Display a date using the short date format specified in your computer's regional settings. |
DateFormat.LongTime | Display a time using the time format specified in your computer's regional settings. |
DateFormat.ShortTime | Display a time using the 24-hour format (hh:mm). |
Exception type | Error number | Condition |
---|---|---|
5 | NamedFormat setting is invalid. |
This example demonstrates the use of the FormatDateTime function.
Dim myDate As DateTime = #2/14/89# Dim myString As String ' Returns "Tuesday, February 14, 1989". myString = FormatDateTime(myDate, DateFormat.LongDate)
FormatCurrency Function | FormatNumber Function | FormatPercent Function |