anyone know whats the best way to get date of birth im only able to find date and time and trying to parse it as a string wont update or delete from the database i get this error
String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid DateTime.
Source Error:
Line 96: int labID = int.Parse(hdfID.Value.ToString()); Line 97: Line 98:
_strMessage(objLab.commitUpdate(labID, txt_patientidI.Text, txt_testCodeI.Text, txt_patientcodeI.Text, txt_ageI.Text, txt_refrangeI.Text, txt_result1I.Text, txt_result2I.Text, txt_resultDescI.Text, txt_sexI.Text, txt_testTypeI.Text, txt_unitsI.Text, txt_abnormalI.Text, Line 99:
(DateTime.ParseExact(txt_dobI.Text,"yyyy/mm/dd",null))),"update"); Line 100: _subRebind();
what should i use for date of birth im using sql server c# .net want to parse that to string to show in my textbox thanks
Try using DateTime.ParseExact
. instead of DateTime.Parse
this.Text="22/11/2009";
DateTime date = DateTime.ParseExact(this.Text, "dd/MM/yyyy", null);
DateTime
is the structure you'll need to use.
Whenever you just want the date, you can use DateTime.Date
to get just the date component.
Now, if you're parsing something in a format which is different to what one would generally expect, you can define the format the parser will look at by using the ParseExact function instead.
DateTime myDate = DateTime.ParseExact(txt_dobI.Text,"dd/MM/yyyy",null);
The list of the actual formats can be obtained from here http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx
However in short
dd/MM/yyyy - British/EU/Lots of Places Format
MM/dd/yyyy - American Format
yyyy/MM/dd - Standard Format
I was working with wpf application I did this and it worked out for me.
DateTime DOB = DateTime.ParseExact(DOBText.Text.ToString(),
"dd/MM/yyyy", CultureInfo.InvariantCulture);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.