Guest adouglas Posted August 13, 2002 Posted August 13, 2002 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. Quote
NicoVB Posted August 13, 2002 Posted August 13, 2002 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. Quote Visit http://www.nico.gotdns.com Now ONLINE!
Guest adouglas Posted August 13, 2002 Posted August 13, 2002 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. Quote
*Gurus* Derek Stone Posted August 14, 2002 *Gurus* Posted August 14, 2002 So do as NicoVB suggested. Use the Format function to ensure the correct date format after the user has input it. Quote Posting Guidelines
Guest adouglas Posted August 14, 2002 Posted August 14, 2002 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.