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 .NET
DescriptionThis example shows how to use the FormatDateTime function in Visual Basic .NET.
KeywordsFormatDateTime, format date, format time, format datetime, VB.NET
CategoriesStrings, VB.NET
 
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, DateFormat.GeneralDate)6/27/2006 10:55:06 AM
FormatDateTime(Now, DateFormat.LongDate)Thursday, June 27, 2006
FormatDateTime(Now, DateFormat.ShortDate)6/27/2006
FormatDateTime(Now, DateFormat.LongTime)10:55:06 AM
FormatDateTime(Now, DateFormat.ShortTime)10:55

This example uses the following code to display these examples in a TextBox.

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Dim txt As String

    txt &= "FormatDateTime(Now, DateFormat.GeneralDate) = " _
        & FormatDateTime(Now, DateFormat.GeneralDate) & _
        vbCrLf
    txt &= "FormatDateTime(Now, DateFormat.LongDate) = " & _
        FormatDateTime(Now, DateFormat.LongDate) & vbCrLf
    txt &= "FormatDateTime(Now, DateFormat.ShortDate) = " & _
        FormatDateTime(Now, DateFormat.ShortDate) & vbCrLf
    txt &= "FormatDateTime(Now, DateFormat.LongTime) = " & _
        FormatDateTime(Now, DateFormat.LongTime) & vbCrLf
    txt &= "FormatDateTime(Now, DateFormat.ShortTime) = " & _
        FormatDateTime(Now, DateFormat.ShortTime) & vbCrLf

    txtResult.Text = txt
    txtResult.Select(0, 0)
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated