Reputation: 61719
DateTime frm_datestart = DateTime.Parse(dateStart.Text);
This line throws the error:
Exception Details: System.FormatException: String was not recognized as a valid DateTime.
Where the entered string is from Jquery-UI, examples:
09/29/2010
09/30/2010
Anyone know what the correct format should be? I'm suprised this isn't working :S
Upvotes: 1
Views: 966
Reputation: 18662
The problem with DateTime.ParseExact() method suggested in previous answers is, it fails on some Cultures. So your application may fail to run correctly on certain Operating Systems.
If you are sure that dateStart.Text will always be in the same format (i.e. en-US), you may try passing appropriate CultureInfo as a second argument. For format "MM/dd/yyyy" use CultureInfo.InvariantCulture.
Upvotes: 0
Reputation: 30873
Use DateTime.ParseExact to specify format like this: DateTime.Parse("dd/MM/yyyy", dateStart.Text, null)
Upvotes: 0
Reputation: 33491
You can use an overloaded version of the DateTime.Parse()
method which accepts a second DateTimeFormatInfo
parameter.
System.Globalization.DateTimeFormatInfo dti = new System.Globalization.DateTimeFormatInfo();
dti.ShortDatePattern = "MM/dd/yyyy";
DateTime dt = DateTime.Parse(dateStart.Text, dti);
Upvotes: 4