I unable to convert string to date, my string like 17/12/2012
Code written for this is shown below
public string Date_Convert(string dt1)
{
string strdate = string.Empty;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
DateTime dt = Convert.ToDateTime(dt1);
strdate = dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString();
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
return strdate;
}
It is working fine in my local system. And not working in my server(which is located at Australia)of course I tried with different culture settings in the above code,
I’m using this date string in sql query in where condition.
please help me, It killed my one day time, and thanks in advance.
Instead of switching the culture, why don’t you do something like this:
Also: If you use the value in an SQL query (and provided that your query works on a
DATETIMEfield, notNVARCHAR), you should also consider using a parameterized query to pass theDateTimevalue to the database to avoid SQL injection.For example: