|
|
Title | Use the FormatDateTime function in Visual Basic 6 |
Description | This example shows how to use the FormatDateTime function in Visual Basic 6. |
Keywords | FormatDateTime, format date, format time, format datetime |
Categories | Strings |
|
|
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):
Expression | Result |
FormatDateTime(Now, vbGeneralDate) | 6/30/06 8:56:46 AM |
FormatDateTime(Now, vbLongDate) | Friday, June 30, 2006 |
FormatDateTime(Now, vbShortDate) | 6/30/06 |
FormatDateTime(Now, vbLongTime) | 8:56:46 AM |
FormatDateTime(Now, vbShortTime) | 08:56 |
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
|
|
|
|
|
|