i am using debugger following is my code when i give input for date dateOfBirth is=10/08/2010 (dd//mm/yy format) but the birthDate variable having value={1/10/2010 12:08:00 AM}
and string outPut have value=08/10/YY
and on taking my debugger to next step to date=Convert.ToDateTime(outPut) it throws exception “The string was not recognized as a valid DateTime. There is a unknown word starting at index 6.”
Whats wrong with all this please let me know how to convert date time format dd/mm/yyyy to date for mate for sql server 2005
following is my code
DateTime? date = null;
if (!string.IsNullOrEmpty(DOB.Text.Trim()))
{
string dateOfBirth = DOB.Text.Trim();
DateTime birthDate = DateTime.ParseExact(dateOfBirth, "dd/mm/yyyy", System.Globalization.CultureInfo.InvariantCulture);
string outPut = birthDate.ToString("mm/dd/YY");
date = Convert.ToDateTime(outPut);
}
From your comment I understand what you are trying to do now, Convert a ‘dd/MM/yyyy’ date to a DateTime, the following code should do it