Why does CDate and parseExact turn today’s date (3rd October), represented as 03/10/2012, into 10/03/2012? I am using Windows 7, VS2012. All my settings in Control Panel are UK/GB. I have tried adding the lines
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB", True)
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-GB", True)
with no effect.
Here is my code – you will see that I have to resort to swapping the day and month of the text version in order to get the date I want
dim txtDate As String = "03/10/2012"
Dim strOriginalDate As String = txtDate ' 03/10/2012
Dim dtmdate1 As Date = CDate(txtDate) ' #10/03/2012#
Dim dtmdate2 As Date = DateTime.ParseExact(txtDate, "dd/MM/yyyy", Nothing) ' #10/03/2012#
txtDate = Split(txtDate, "/")(1) & "/" & Split(txtDate, "/")(0) & "/" & Split(txtDate, "/")(2)
Dim dtmdate3 As Date = CDate(txtDate) ' #3/10/2012#
I suspect that you are looking at the date values in the Locals pane of the debugger. If you actually write out the values you will find they are as required:
The final line of output is, of course, not as desired because you have swapped the month and day.
Tested with VS2012 RC on W7 x64 set to en-GB. You might want to test with setting VS’s locale: http://msdn.microsoft.com/en-US/library/9cytz106%28v=vs.80%29.aspx
The display of the date as a date literal is entirely consistent with how a data literal is defined, for example see the Format Requirements subsection of Date Data Type (Visual Basic)