Question

We have some legacy code that can't really be altered which "forces" the user to enter a date in MM/dd/yyyy format through ValidationExpression and a regex on the text field.

However, the C# code will be expecting the date in either MM/dd/yyyy or dd/MM/yyyy depending on the region.

I need to format the entered date into the region specific date.

Any ideas?

So far I've tried DateTime enteredDate = DateTime.ParseExact(StartDateTextBox.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture); but that returns as error stating that "09/04/2013" is not a recognised date.

Was it helpful?

Solution

Replace CultureInfo.InvariantCulture with null.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top