Hi,

I have the following data in a excel csv file:

Date,Time,TempOut
3/17/2011,00:30,73.3

However, if I load it using:

ExclConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
                                            "Data Source=" + dir + ";" +
                                            "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";

Then:

string Data = "SELECT * FROM [" + FileName + "]";
                OleDbDataAdapter dtadpt = new OleDbDataAdapter(Data, ExclConn);
                //Create table
                dtadpt.Fill(dt);

If I display,

dt.Rows[0][1].ToString()

It shows 12/30/1899 12:30 AM instead just 00:30.

Any solution to this?

It happens when format of your input doesn't match your system's default time format check that.

dt.Rows[0][1].ToString("hh:mm");
dt.Rows[0][1].ToString("hh:mm");

It said: 'No overload method takes 1 argument'.
So I tried this: dt.Rows[0][1] = String.Format("{0:hh:mm:ss}", dt.Rows[0][1].ToString()); However, it insist on typing the date together with the time...

if it is right then simply take it and after that split the string into date and time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.