I have one maskedtextbox in windows application 2010 in which i have entered date in dd/mm/yyyy format and converted it in
mm/dd/yyyy
format(because sql 2008 database accept date in mm/dd/yyyy format) to submit it successfully in sql 2008 database as follows:-for eg
25/09/2013
NOTE :-MY SYSTEM DATE IS ALSO IN DD/MM/YYYY FORMAT
private void btn_submit_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("INSERT INTO date (discharge_date) values (CONVERT(smalldatetime, '" + maskedtxbx_dischargedate.Text + "', 103))", con);
cmd.Parameters.AddWithValue("@discharge_date", maskedTextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records inserted");
}
private void btn_retreive_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from date where discharge_date= '"+maskedTextBox1.Text+"'", con);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
da.Fill(dtusers);
dataGridView1.DataSource = dtusers;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
Now comes the second part i.e when MY SYSTEM DATE FORMAT IS IN MM/DD/YYYY FORMAT I have entered date in
dd/mm/yyyy
format in the same maskedtextbox and after that i have clicked the retrieve button so that the dischargedate entered in maskedtextbox should match with the date saved in sql database and then the matching dischargedates should show in gridview.
But when I enter
25/09/2013
it retrieves the results in gridview in mm/dd/yyyy format i.e 09/24/2013
So my question is: what is the role of SYSTEM DATE FORMAT in Microsoft Visual studio 2010 Windows application and sql 2008 databases when we are already using DATETIME CONVERT FUNCTIONS
AS 103. WHAT TO DO WHEN SYSTEM DATE FORMAT IS IN MM/DD/YYYY FORMAT?
[EDIT]Do not SHOUT![/EDIT]