I have stored date of birth var char format:
Example: 1989-8-15
I want to find out sub string from it i.e I want separate year, month and date. I have tried it with following code:
string dateOfbirth = (string)(DataBinder.Eval(e.Item.DataItem, "dob"));
int length = (dateOfbirth).Length;
int index1 = dateOfbirth.IndexOf('-');
int index2 = dateOfbirth.IndexOf('-', index1 + 1);
string year = dateOfbirth.Substring(0, index1);
string month = dateOfbirth.Substring(index+1, index2-1);
string day = dateOfbirth.Substring(index2, length);
I am getting an error. Please suggest a solution. Thanks in advance.
string[] arrDateOfbirth = dateOfbirth.Split('-');Then you can select a value by stepping through the array...