Parsing user date input

A

adouglas

Guest
I've got a textbox into which the user can enter a date. Whenever I try to convert the text from this textbox into a Date using Date.Parse or CDate, it insists on reading it as Month/Day/Year, even though my PC's regional settings are set up to be Day/Month/Year. How can I make VB.NET read the date properly without getting the Day and Month mixed up?

Thanks.
 

NicoVB

Centurion
Joined
Jan 2, 2002
Location
Belgium
You can use the format function in VB.NET with the combination of a format string. You have to look in the help of VB.NET to know exactly the string. It's something like "d" or "dd" and so on.

But then you will be able to convert your date into the right setting.
 
A

adouglas

Guest
No, that's not the problem. Format is used for outputting a date in the format you specify. My problem is reading in a date. The user enters a date into a textbox, and I need to read it into a date variable. The trouble is, all the functions I can find which will do this seem to assume that the date is being entered in month/day/year format, so if the user enters "9/8/2002", the date variable that gets created is 8th September, 2002, when it should actually be 9th August, 2002. I'm pretty sure VB6 used the regional settings on your computer to determine what format to read the date as, but VB.NET seems to assume that the entire world is using the American date format instead of looking in the regional settings.
 
A

adouglas

Guest
Thanks to both of you for replying. I actually just found the solution this very minute. Instead of

Date.Parse(datestring)

I needed to use

Date.Parse(datestring, System.Globalization.Cultureinfo. CurrentCulture). This CurrentCulture object seems to contain all the regional settings related information.
 
Top Bottom