Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:43:04+00:00 2026-05-29T05:43:04+00:00

In excel sheet i have date in format dd.MM.yyyy 16.10.2011 (16 as dd, 10

  • 0

In excel sheet i have date in format dd.MM.yyyy 16.10.2011 (16 as dd, 10 as MM). When i’m importing data from excel to SQL Server 2008 i get MM.dd.yyyy but still 16.10.2011 (16 as MM, 10 as dd). That’s not correct. I found solution on this: go to SQL Server 2008 -> Security -> logins -> {user properties} -> and change default language for user. With this solution i get in SQL Server 2008 dd.MM.yyyy 16.10.2011 (16 as dd, 10 as MM). Is there any other way to convert date in dd.MM.yyyy format without changing user language?

String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\JantarV7Export.xlsx;Extended Properties=Excel 8.0";
OleDbConnection olecon = new OleDbConnection(sConnectionString);

olecon.Open();
OleDbCommand cmd = olecon.CreateCommand();
cmd.CommandText = "SELECT person_id, date_of_hours, number_of_hours FROM [Sheet1$]";                    
OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
OleDbDataReader odr = cmd.ExecuteReader();
conn.Open();
while (odr.Read())
{
    SqlCommand cmd1 = conn.CreateCommand();

    cmd1.CommandText = "INSERT INTO test_data values (newid(),'" + odr[0] + "',@date_of_hours,'" + odr[2] + "')";
    cmd1.Parameters.Add("@date_of_hours", SqlDbType.DateTime).Value =odr[1];
}
cmd1.ExecuteNonQuery();
olecon.Close();
conn.Close();

I think that problem is when i’m inserting into test_data datatable. So i probably should convert dates somehow before inserting. What do you suggest? Thanks. Is there any options like this:

cmd1.CommandText = "INSERT INTO test_data values (newid(),'" + odr[0] + 
    "',CONVERT(VARCHAR(20),@date_of_hours,104),'" + odr[2] + "')";
cmd1.Parameters.Add("@date_of_hours", SqlDbType.DateTime).Value =odr[1];

(this doesn’t work because of CONVERT in insert, but is there some similar solution) or

CONVERT(VARCHAR(20),@date_of_hours,104) AS [DD:MM:YYYY]

UPDATE
In other form i read data through combobox. It shows 1.10.2011, 2.10.2011, …. to 16.10.2011.

da_test_data = new SqlDataAdapter("SELECT test_data_id, date_of_hours, number_of_hours FROM test_data WHERE _person_id= '" + person_id_person + "' ORDER BY date_of_hours", conn);
dt_test_data = new DataTable();
da_test_data.Fill(dt_test_data);
cb_datum.DataSource = dt_test_data.DefaultView;
cb_datum.ValueMember = "test_data_id";
cb_datum.DisplayMember = "date_of_hours";

And combobox for projects:

 private void cb_datum_SelectedIndexChanged(object sender, EventArgs e)
 {
      DataRowView drvProjekt = cb_datum.SelectedItem as DataRowView;
      if (drvProjekt != null)
      {
          string date1 = drvProjekt["date_of_hours"].ToString();  
          DateTime date2 = new DateTime();
          date2 =Convert.ToDateTime(date1);

          //DateTime date = DateTime.ParseExact(date1, "MMddyyyy hh:mm:ss", null);
          //DateTime date = DateTime.ParseExact(date1, "dd.MM.yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

          //object obj = DateTime.ParseExact(dddd, "MM/dd/yyyy hh:mm", null);
          conn = new SqlConnection(connectionString);
          conn.Open();

          da_projekt = new SqlDataAdapter("SELECT projekt_id, name_of_projekt, date_of_start, date_of_end FROM projekt WHERE date_of_start < '" + date2 + "' AND date_of_end > '" + date2 + "' ", conn);
          dt_projekt = new DataTable();
          da_projekt.Fill(dt_projekt);
          cb_projekt_id.DataSource = dt_projekt.DefaultView;
          cb_projekt_id.ValueMember = "projekt_id";
          cb_projekt_id.DisplayMember = "name_of_projekt";
          conn.Close();
      }
 }

When i select 13.10.2011 i get error. Date is recognised as MM.dd.yyyy. I tried everything (all in comments and many more). Yust don’t find a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:43:05+00:00Added an answer on May 29, 2026 at 5:43 am

    As I mentioned in the comment. your date value is stored as Date in SQL. So when you store date in SQL it will remain date only, and when you retrieve it you will get date object directly. In SQL, it might be displayed as MM.dd.yyyy it doesn’t matter.

    When you will read this data from SQL, you will get DateTime object, on this if you do .ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) you will get in dd.MM.yyyy format. You can use any format on DateTime object, read more about it on MSDN.

    Hope this answers your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am preparing myself for importing data from excel sheet to sql server 2005.I
I have get the date from excel sheet using POI using the below code,
I am importing Excel sheet into DataGridView.I have one of the cell has date
I'm importing data from an Excel sheet on to a DataTable using the following
I have data in an excel sheet in the following format: ItemCode DeliveryDate 5456987
I am working on importing data from an Excel sheet to database. The Excel
I am importing an Excel sheet into a SQL Server database. I am able
I have to export each and every data to excel sheet or ant format
i have export a excel sheet which will collect data from my customer table
In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.