storing datetime in sql from asp.net
-
i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-:
using System.Globalization;
IFormatProvider culture = new CultureInfo("fr-FR", true);
DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));
Maniiiiiiiiiiiiiii
-
i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-:
using System.Globalization;
IFormatProvider culture = new CultureInfo("fr-FR", true);
DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));
Maniiiiiiiiiiiiiii
Use the Invariant culture to store the date...
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Use the Invariant culture to store the date...
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
How?
Maniiiiiiiiiiiiiii
-
i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-:
using System.Globalization;
IFormatProvider culture = new CultureInfo("fr-FR", true);
DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));
Maniiiiiiiiiiiiiii
i have found this in some replies but dat was not working. I always use ISO format when typing SQL in Query Analyzer, but for accessing the application through ADO.NET (ASP.NET is for web applications and has nothing to do with the database). I don't worry about the date format as I use parameters. For example SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; cmd.CommandText = "SELECT * FROM MyTable "+ "WHERE SomeDate BETWEEN @startDate AND @endDate"; cmd.Parameters.Add("@startDate", theStartDateTimeObject); cmd.Parameters.Add("@endDate", theEndDateTimeObject); SqlDataReader reader = cmd.ExecuteDataReader(); theStartDateTimeObject and theEndDateTimeObject are DateTime objects. If you use these then you don't need to know what format to write the dates in to the SQL String - and nor should you need to convert it. The database should be used for storing information. You shouldn't really be doing any localisation functions with the database as that is all presentation layer stuff.
Maniiiiiiiiiiiiiii