I have a situation in which I need to convert a text data into date.
I have used the following code to do so!
string s = textBox1.Text;
if (String.IsNullOrEmpty(s))
{
textBox2.Text = "Please enter any date.";
}
else
{
DateTime dt = DateTime.Parse(s);
string day = dt.Day.ToString();
string month = dt.Month.ToString();
string year = dt.Year.ToString();
s = day + "/" + month + "/" + year;
textBox2.Text = s;
}
This will change only the following formats of data.
10/10/09 or 10/10/2009----converted date------10/10/2009
12/13/2009 or 12/13/9----converted date-------12/13/2009
10/16----converted date-----------------------16/10/2009
2009/12/10----converted date------------------10/12/2009
The following formats are not getting changed to dd/mm/yyyy
16/10-dd/mm
060209 or 06022009 ddmmyyyy
13122009 mmddyyyy
20091213 yyyymmdd
20091312 yyyyddmm
20.07.2009/20.07.2009/20-07-2009/20-07-09
Can anyone help me out with this. I am very new to c#