I am writing this code the text Change event but it is showing the error that is string is not valid.
DateTime ts=Convert.ToDateTime(Joiningdate.Text);
DateTime dt1=ts.AddMonths(6);
txtcd.Text = dt1.ToShortDateString();
I am writing this code the text Change event but it is showing the error that is string is not valid.
DateTime ts=Convert.ToDateTime(Joiningdate.Text);
DateTime dt1=ts.AddMonths(6);
txtcd.Text = dt1.ToShortDateString();
The DataTime format does not match the format you need to convert string to DateTime object. You can use DateTime.ParseExact() to give you format you date you have.
Assuming you have format dd/MM/YY for the textbox
DateTime ts= DateTime.ParseExact(Joiningdate.Text, "dd/MM/yy", CultureInfo.InvariantCulture);
DateTime dt1=ts.AddMonths(6);
txtcd.Text = dt1.ToShortDateString();
The problem is with the format of Joiningdate.Text
You will have to tell that in what format your date time is.
If your date time is in format use
DateTime ts= DateTime.ParseExact(Joiningdate.Text, "ddMMyyyy",
CultureInfo.InvariantCulture);
DateTime dt1=ts.AddMonths(6);
nd then you can convert back to any format you want
ts.ToString("yyyyMMdd");
You can go through this link