Formatting

Dim sResult As String 
sResult = System.String.Format("{0:MM\/dd\/yyyy}", System.DateTime.Now())
sResult = "01/06/2002"


Formatting Dates


Dim dtDateTime As System.DateTime 
dtDateTime As New System.DateTime(2002, 1, 6, 18, 30, 20)


ToLongDateString

This format does not always display correctly and will depend on local settings.
It only displays the following format when the settings are US

System.DateTime dtDateTime; 
dtDateTime = new System.DateTime(2020,1,6,18,30,20);
dtDateTime.ToLongDateString = "Sunday, January 06, 2020"

When the settings are UK the format is as follows:

dtDateTime.ToLongDateString = "January 06, 2002" 

ToShortDateString

This format does not always display correctly and will depend on local settings.

dtDateTime.ToShortDateString = 01/06/2002 

ToString

Again there are 2 different ways

Dim sDateString As String 
sDateString = Now().ToString("dd mmm yy")
sDateString = System.DateTime.ToString(Now())

DateTimeFormatInfo

Defines how DateTime values are formatted and displayed
Added in .NET 2.0



Other Formats

dtDateTime.ToShortTimeString = 6:30 PM 
dtDateTime.ToLongTimeString = 6:30:20 PM
dtDateTime.ToFileTime = 126548334205000000
dtDateTime.ToOADate = 37262.7710706019
dtDateTime.ToUniversalTime = 1/6/2002 11:30:20 PM
dtDateTime.ToLocalTime = 1/6/2002 1:30:20 PM


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext