Microsoft KB Archive/889833

= The DateString function does not change supported Date formats in Visual Basic .NET or in Visual Basic 2005 =

Article ID: 889833

Article Last Modified on 11/16/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





SYMPTOMS
The DateString function does not change supported Date formats. The date string that is returned by the DateString function does not take into consideration Regional Options in Control Panel and that all dates that are returned from the call are in the MM-dd-yyyy format. This problem occurs in Microsoft Visual Basic .NET 2002, in Microsoft Visual Basic .NET 2003, and in Microsoft Visual Basic 2005.



CAUSE
This problem occurs because the DateString function is culture-invariant. Therefore, you cannot change the supported Date formats. This is true even if you change Regional Options in Control Panel.

The following Date formats are supported:
 * M-d-yyyy
 * M-d-y
 * M/d/yyyy
 * M/d/y



RESOLUTION
To resolve this problem, use the Format function. The following code example shows various uses of the Format function. The Format function can format values by using both string formats and user-defined formats. Dim MyDateTime As Date = #1/27/2001 5:04:23 PM# Dim MyStr As String ' The current system time is returned in the system-defined long time format. MyStr = Format(Now, &quot;Long Time&quot;) ' The current system date is returned in the system-defined long date format. MyStr = Format(Now, &quot;Long Date&quot;) ' The current system date is also returned in the system-defined long date ' format by using the single letter code for the format. MyStr = Format(Now, &quot;D&quot;) ' The value of MyDateTime is returned in user-defined date format and in user-defined time format. MyStr = Format(MyDateTime, &quot;h:m:s&quot;)  ' Returns &quot;5:4:23&quot; MyStr = Format(MyDateTime, &quot;hh:mm:ss tt&quot;)  ' Returns &quot;05:04:23 PM&quot; MyStr = Format(MyDateTime, &quot;dddd, MMM d yyyy&quot;)  ' Returns &quot;Saturday, ' Jan 27 2001&quot; MyStr = Format(MyDateTime, &quot;HH:mm:ss&quot;)  ' Returns &quot;17:04:23&quot; MyStr = Format(23)  ' Returns &quot;23&quot; ' User-defined numeric formats follow. MyStr = Format(5459.4, &quot;##,##0.00&quot;)  ' Returns &quot;5,459.40&quot; MyStr = Format(334.9, &quot;###0.00&quot;)  ' Returns &quot;334.90&quot; MyStr = Format(5, &quot;0.00%&quot;)  ' Returns &quot;500.00%&quot;



STATUS
This behavior is by design.



MORE INFORMATION
For additional information about date format and time format, visit the following Microsoft Developer Network (MSDN) Web sites:

DateTimeFormatInfo class

http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo(vs.71).aspx

Date and time changes in Visual Basic

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vacondatetimechangesinvisualbasic.asp

Format function

http://msdn2.microsoft.com/en-us/library/59bz1f0h(vs.71).aspx

Formatting date and time for a specific culture

http://msdn2.microsoft.com/en-us/library/5hh873ya(vs.71).aspx

Keywords: kbvs2005swept kbvs2005applies kbtshoot kbprb KB889833

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.