Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UK Date Format

Status
Not open for further replies.

markknowsley

Programmer
Joined
Aug 30, 2005
Messages
152
Location
GB
Please can someone help because this is driving me nuts. I've got three text boxes which take date in the format dd/mm/yyyy. I check to see that all the inputs are numeric, then parse the date thus:

if ((v.IsNumeric(txtDay.Text) == true) && (v.IsNumeric(txtMonth.Text) == true) && (v.IsNumeric(txtYear.Text) == true))
{
CultureInfo ukCulture = new CultureInfo("en-GB");
DateTime dtDateTime = DateTime.Parse(txtDay.Text + "/" + txtMonth.Text + "/" + txtYear.Text, ukCulture.DateTimeFormat);
}

On the local VS 2005 web server this works fine. But as soon as I copy the web form to an IIS web server and enter a date like 31/01/2006 I get the following error message:
"String was not recognized as a valid DateTime"

I thought that the 'en-GB' culture was supposed to stop this happening - any ideas?
 
How about:

Code:
DateTime dtDateTime = new DateTime(Convert.ToInt32(txtYear.Text), Convert.ToInt32(txtMonth.Text), Convert.ToInt32(txtDay.Text));

?

Nelviticus
 
what about
Code:
CultureInfo info = new CultureInfo("en-GB");
DateTime birthDate = DateTime.ParseExact(date, "d/M/yyyy", info);
this will except dd/mm/yyyy or d/m/yyyy BTW "date" (the first arg ) is a string

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top