The FormatDateTime function returns a formatted string representation for a date and/or time. The syntax is:
FormatPercent(expression [, format] )
Where:
expression
The numeric expression to format
format
A date/time formatting value
The result depends on your system's locale. Examples (in the United States):
This example uses the following code to display these examples in a TextBox.
Private Sub Form_Load() Dim txt As String txt = txt & "FormatDateTime(Now, vbGeneralDate) = " & _ FormatDateTime(Now, vbGeneralDate) & vbCrLf txt = txt & "FormatDateTime(Now, vbLongDate) = " & _ FormatDateTime(Now, vbLongDate) & vbCrLf txt = txt & "FormatDateTime(Now, vbShortDate) = " & _ FormatDateTime(Now, vbShortDate) & vbCrLf txt = txt & "FormatDateTime(Now, vbLongTime) = " & _ FormatDateTime(Now, vbLongTime) & vbCrLf txt = txt & "FormatDateTime(Now, vbShortTime) = " & _ FormatDateTime(Now, vbShortTime) & vbCrLf txtResults.Text = txt End Sub