There are some problems that developers face while sending
date from VS Studio to Sql Server database. Here is a simple format by which
you can change date easily to database acceptable format.
Code:-
public void getDate()
{
DateTime newDate = Convert.ToDateTime(ChangeDateFormat(txtNewDate.Text, '/'));
}
public string ChangeDateFormat(string date, char delimeter)
{
char delim='/';
string dateSeparator = null;
dateSeparator = date.Substring(date.Length - 4, 1);
if (dateSeparator == "/" || dateSeparator == "-" || dateSeparator == ".")
delim = Convert.ToChar(dateSeparator);
string[] strDate = Convert.ToString(date).Split(delim);
string nDate = strDate[1] + "/" + strDate[0] + "/" + strDate[2];
return nDate;
}
No comments:
Post a Comment