A
Assimalyst
Hi,
I am trying to convert a UK formated date in a textbox to sql server
format. dd/MM/yyyy -> yyyyMMdd.
Here's the code:
IFormatProvider format = new System.Globalization.CultureInfo("en-GB",
true);
DateTime dateUK = DateTime.ParseExact(DOBTxtBx.Text, "dd/MM/yyyy",
format);
string dateSQL = dateUK.ToString("yyyyMMdd");
// Insert data to dataset table row
patientRow["pntDOB"] = dateSQL;
If, for instance DOBTxtBx.Text = 21/09/1909
Stepping through with debugger gives:
dateUK = 9/21/1909 (this does not seem to be correct, it's MM/dd/yyyy
???)
dateSQL = 19090921 (this does seem OK!)
But the program then errors on patientRow["pntDOB"] = dateSQL; saying
'String was not recognised as a valid DateTime'.
Any ideas what the problem is?
Many Thanks
I am trying to convert a UK formated date in a textbox to sql server
format. dd/MM/yyyy -> yyyyMMdd.
Here's the code:
IFormatProvider format = new System.Globalization.CultureInfo("en-GB",
true);
DateTime dateUK = DateTime.ParseExact(DOBTxtBx.Text, "dd/MM/yyyy",
format);
string dateSQL = dateUK.ToString("yyyyMMdd");
// Insert data to dataset table row
patientRow["pntDOB"] = dateSQL;
If, for instance DOBTxtBx.Text = 21/09/1909
Stepping through with debugger gives:
dateUK = 9/21/1909 (this does not seem to be correct, it's MM/dd/yyyy
???)
dateSQL = 19090921 (this does seem OK!)
But the program then errors on patientRow["pntDOB"] = dateSQL; saying
'String was not recognised as a valid DateTime'.
Any ideas what the problem is?
Many Thanks