Dear All,

I am trying to read a CSV file into VB.NET datagridview which is fine i did already but one of datagridview coloumn is date and time i want to convert it to human readable format and want to read the correct format in date and time column in all rows like if i have 100 records it should correct or convert all 100 records date and time into correct format in that column and the column number is 4.

Any sample code example will be much appriciated.

I did conversion in excel by using the below formula it works fine and shows correct format,

=(B2/86400)+25569) which brings me correct format.

Please help on this.

Many Thanks in advance.

Recommended Answers

All 7 Replies

I tried this before but it's bringing same result for all my cell in that coloumn

 Private Sub calculation()
        Dim dt As Date
        dt = New DateTime(1970, 1, 1, 0, 0, 0, 0)
            Dim i As Integer

        For Each row As DataGridViewRow In DataGridView1.Rows
            If Not row.IsNewRow Then
                DataGridView1.Rows(i).Cells(4).Value = dt
                i += 1
            End If
    End Sub

Please help on this i need to put the formula as i submitted in my first post.

Many Thanks.

Let's read your code. You declare dt in line 3. From there to line 8, dt never changes so all columns should be the same value.

As to fixing your code, I think the 3 lines I read at supplied link could be used.

Sorry i didn't get you if you can modify this code and explain a ittle bit it will be great.


Move line 3 to just before line 8. Then after that add your UNIX time like this.
dt = dt.AddSeconds(timestamp); //timestamp is your UNIX time value from your file.

You should be able to read files and all that so let's see you fix that up too.

Of course if you didn't read my supplied link, you will be lost.

commented: Great help +15

actualy the time i am fetching from the csv file its in a raw format once i add
dt = dt = dt.AddSeconds(DataGridView1.Rows(i).Cells(4).Value)

i am getting error on this line "Conversion from string "dateTimeOrigination" to type 'Double' is not valid."

And in the link I provided it notes what data types to use. Your line of code may have to add a conversion. Check the only link I gave you.

Be a part of the DaniWeb community

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