Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse the FormatDateTime function in Visual Basic 6
DescriptionThis example shows how to use the FormatDateTime function in Visual Basic 6.
KeywordsFormatDateTime, format date, format time, format datetime
CategoriesStrings
 
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):

ExpressionResult
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
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated