Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMaria Kochetygova
Courses Plus Student 1,784 PointsConvert String into DateTime
patinet.addPatient(textBox1.Text, textLastName.Text, textID.Text, textIncuranceName.Text, textNumberInsurance.Text, textDOB.DateTime); how do I convert txtDOB.DateTime to string so I won't though me an error.
Thank you.
2 Answers
Steven Parker
231,248 Pointswhat kind of thing is textDOB? Does it perhaps have a Text property? If so, you may be able to do this:
patient.addPatient(textBox1.Text, textLastName.Text, textID.Text, textIncuranceName.Text, textNumberInsurance.Text, textDOB.Text);
Otherwise, I'd be inclined to try:
patient.addPatient(textBox1.Text, textLastName.Text, textID.Text, textIncuranceName.Text, textNumberInsurance.Text, textDOB.DateTime.ToShortDateString());
and if that didn't work (or you needed more than just a date), try Pablo's suggestion:
patient.addPatient(textBox1.Text, textLastName.Text, textID.Text, textIncuranceName.Text, textNumberInsurance.Text, textDOB.DateTime.ToString());
Pablo Rocha
10,142 PointsHi Maria Kochetygova - Is this tied to a quiz? I cannot find it.
In the simplest way you can perform the following code to turn a DateTime into a string.
string myString = textDOB.DateTime.ToString();
However, for the correct answer we would need more context in regards to what method addPatient is expecting because there are many ways to format a date as a string. Click on this link for some examples.