title: c# exporting datetime from datagridview to excel greek regional setting
body: <p>My issue is that,
  I have the mysql database and when i insert data:</p>
  
  <blockquote>
    <p>string date = dateTimePicker1.Value.ToString("yyyy:MM:dd");</p>
  </blockquote>
  
  <pre><code>MySqlCommand cmd = new MySqlCommand ("INSERT INTO EXPENSES (ID, E_DATE, AMMOUNT, PERSON, COMMENTS, T_ID) VALUES (@id, @date,@ammount, @person, @comments, @tid)",myMySqlConnection);
                      cmd.Parameters.AddWithValue("@id", id);
                      cmd.Parameters.AddWithValue("@date", date);
                      cmd.Parameters.AddWithValue("@ammount", ammount);
                      cmd.Parameters.AddWithValue("@person", person);
                      cmd.Parameters.AddWithValue("@comments", comments);
                      cmd.Parameters.AddWithValue("@tid", tid);
                      cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>when i view them in datagridview:</p>
  
  <pre><code>string test = startdate1.ToString("yyyy:MM:dd");
          string test2 = enddate1.ToString("yyyy:MM:dd");
          DataTable table1 = new DataTable();
          cmd1 = new MySqlCommand("SELECT E_DATE, AMMOUNT, PERSON, COMMENTS, T_ID FROM EXPENSES WHERE DATE (E_DATE) BETWEEN '" + test + "' AND '" + test2 + "' AND ID =@userid ORDER BY E_DATE ASC", myMySqlConnection);            
          cmd1.Parameters.AddWithValue("@userid", id);
          da1.SelectCommand = cmd1;
          da1.Fill(table1);
          BindingSource bSource1 = new BindingSource();
          bSource1.DataSource = table1;
          dataGridView1.DataSource = bSource1;
  </code></pre>
  
  <p>now i want to export them in excel:</p>
  
  <pre><code>Excel_12.Application oExcel_12 = null;
              Excel_12.Workbook oBook = null;
              Excel_12.Sheets oSheetsColl = null;collection
              Excel_12.Worksheet oSheet = null;
              Excel_12.Range oRange = null;
              Object oMissing = System.Reflection.Missing.Value;
              oExcel_12 = new Excel_12.Application();
              oExcel_12.Visible = true;
              oExcel_12.UserControl = true;
              System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
              oBook = oExcel_12.Workbooks.Add(oMissing);
              oSheetsColl = oExcel_12.Worksheets;
              oSheet = (Excel_12.Worksheet)oSheetsColl.get_Item("Sheet1");
              // Export titles
              for (int j = 0; j &lt; myDataGridView.Columns.Count; j++)
              {
                  oRange = (Excel_12.Range)oSheet.Cells[4, j + 1];
                  oRange.Value2 = myDataGridView.Columns[j].HeaderText;
                  oRange.Cells[1].ColumnWidth = 13;
  
              }
              // Export data
              for (int i = 0; i &lt; myDataGridView.Rows.Count; i++)
              {
                  for (int j = 1; j &lt; myDataGridView.Columns.Count; j++)
                  {
                      oRange = (Excel_12.Range)oSheet.Cells[i + 5, j + 1];
                      oRange.Value2 = myDataGridView[j, i].Value;
                  }
              }//This is for everything except the dates
  
              for (int i = 0; i &lt; myDataGridView.Rows.Count; i++)
              {
                  for (int j = 0; j &lt; 1; j++)
                  {
  
                      oRange = (Excel_12.Range)oSheet.Cells[i + 5, j + 1];
                      oRange.Cells[1].NumberFormat = "dd/MMM/yyyy;@";
                      DateTime test = Convert.ToDateTime( myDataGridView[j, i].ToString(),ci);
                      oRange.Value2 = test; //test.Remove(test.Length - 11);
                   //   oRange.NumberFormat = "dd-MM-yyyy";
                  }
              }//This is for the dates
  
              //oBook.Close(false, oMissing, oMissing);
              oBook = null;
              //oExcel_12.Quit();
              oExcel_12 = null;
              // Collect garbage.
              GC.Collect();
  </code></pre>
  
  <p>The problem is that, when the Regional settings are set to GREEK, Excel doesn't recognize the number format for the dates. If the Regional Settings are set to English -US there is no problem with the dates. How can i make it recognize the date without having to worry about the computer's Regional Settings.Any help would be truly appreciated since these Greek are driving me crazy.
  Best Regards
  George Georgiou</p>